MultiPicklist Lightning Experience Problem Solved


When we create a Visualforce Page and in which we can use Multipicklist. It work well in Salesforce Classic but somehow not work in Lightning Experience. We can say a small bug in Salesforce. But every problem has a solution. So, here is the solution below: Demo Video : https://youtu.be/OwWT2WkrsiY

Apex Class


public class MultipicklistSelect{
    public list<SelectOption> lstHobbiesOption {get;set;}
    public Account acc {get;set;}
    public List<String> lstSelectedHobbies {get;set;}
   
   
    public MultipicklistSelect(){
        fetchTrainedBy();
        acc = new Account();
        lstSelectedHobbies = new List<String>();
    }
   
    public void fetchTrainedBy(){
       
        lstHobbiesOption = new List<SelectOption>();
       
        Schema.DescribeFieldResult fieldResult =
            Account.Hobbies__c.getDescribe();
        List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
       
        for( Schema.PicklistEntry f : ple){
            lstHobbiesOption.add(new SelectOption(f.getLabel(), f.getValue()));
        }      
    }
   
   
    public pageReference doSave(){
        String trainedBy = '';
        Boolean Start = true;
        if(!lstSelectedHobbies.isEmpty()) {          
            for(String Str : lstSelectedHobbies) {
                if(Start) {
                    trainedBy = Str;
                    Start = false;
                } else {              
                    trainedBy = trainedBy + ';' + Str;
                }
            }
        }
        acc.Hobbies__c = trainedBy;
        insert acc;
       
        pageReference pg = new pagereference('/'+acc.id);
        pg.setRedirect(false);
        return pg;
    }
}


Visualforce Page:

<apex:page controller="MultipicklistSelect" cache="false" showHeader="false" sidebar="false">
    <html>
        <head>
            <title>Create Candidate</title>
            <meta charset="utf-8"/>
            <meta name="viewport" content="width=device-width, initial-scale=1"/>
            <apex:stylesheet value="{!URLFOR($Resource.MultipicklistSelect,'css/bootstrap.min.css')}"/>
            <apex:includeScript value="{!URLFOR($Resource.MultipicklistSelect,'js/jquery-2.2.4.min.js')}"/>
            <apex:includeScript value="{!URLFOR($Resource.MultipicklistSelect,'js/bootstrap.min.js')}"/>
            <apex:styleSheet value="{!URLFOR($Resource.MultipicklistSelect,'css/bootstrap-multiselect.css')}"/>
            <apex:includeScript value="{!URLFOR($Resource.MultipicklistSelect,'js/bootstrap-multiselect.js')}"/>
            <style>
                .form-group{
                padding:1% !important;
                }
                .scrollBar{
                max-height: 18rem;
                overflow-y: auto;
                }
                .btn-default {
                color: #333 !important;
                background-color: #fff !important;
                border-color: #ccc !important;
                }
               
                .btn {
                display: inline-block !important;
                margin-bottom: 0!important;
                font-weight: normal !important;
                text-align: center !important;
                vertical-align: middle !important;
                touch-action: manipulation !important;
                cursor: pointer !important;
                background-image: none !important;
                border: 1px solid transparent ;
                white-space: nowrap !important;
                padding: 6px 12px !important;
                font-size: 14px !important;
                line-height: 1.42857143 !important;
                border-radius: 4px !important;
                -webkit-user-select: none !important;
                -moz-user-select: none !important;
                -ms-user-select: none !important;
                user-select: none !important;
                }
            </style>
        </head>
        <body>
           
            <apex:form id="frm">
                <div class="form-group">
                    <label class="control-label col-sm-2" for="yrOfGrad">Name</label>
                    <div class="col-sm-6">
                        <apex:inputField value="{!acc.Name}" styleclass="form-control" required="true" id="yrOfGrad"/>
                    </div>
                </div>
                <div class="form-group" style="margin-bottom: 4.5% !important;">
                    <label class="control-label col-sm-2" for="trainedas">Hobbies</label>
                    <div class="col-sm-6">
                        <apex:selectList value="{!lstSelectedHobbies}" id="demo" styleclass="demo" multiselect="true" size="5">
                            <apex:selectOptions value="{!lstHobbiesOption}"/>
                        </apex:selectList>
                    </div>
                </div>
                <center>
                <apex:commandButton id="creg" action="{!doSave}"  styleClass="btn btn-default" value="Save" />
                </center>
            </apex:form>
           
            <script type="text/javascript">
                $(document).ready(function() {
                    $('.demo').multiselect({
                       optionLabel: function(element){
                            return $(element).attr('label') || $(element).text();
                        },
                       
                        onChange : function(option, checked) {
                            console.log("@console.log-->option:"+JSON.stringify(option));
                            console.log("@console.log-->option:"+(option).val());
                            console.log("@console.log-->checked:"+checked);
                        },
                       
                        onDropdownShow: function(event) {
                           
                        },
                       
                        onDropdownHide: function(event) {
                           
                        },
                       
                        onDropdownShown: function(event) {
                           
                        },
                       
                        onDropdownHidden: function(event) {
                           
                        },
                       
                        onSelectAll: function() {
                           
                            console.log('@console.log-->ALlSelectedVales:'+($('[Id$=demo]').val()));
                        },
                        enableHTML: false,
                        buttonClass: 'btn btn-default',
                        inheritClass: false,
                        buttonWidth: 'auto',
                        buttonContainer: '<div class="btn-group" />',
                        dropRight: false,
                        selectedClass: 'active',
                        
maxHeight: false,
                        //checkboxName: false,
                        includeSelectAllOption: false,
                        includeSelectAllIfMoreThan: 0,
                        selectAllText: ' Select all',
                        selectAllValue: 'multiselect-all',
                        includeSelectAllOption:true,
                        selectAllName: true,
                        selectAllNumber: true,
                        enableFiltering: true,
                        enableCaseInsensitiveFiltering: false,
                        enableClickableOptGroups: false,
                        filterPlaceholder: 'Search',
                        // possible options: 'text', 'value', 'both'
                        filterBehavior: 'text',
                        includeFilterClearBtn: true,
                        preventInputChangeEvent: false,
                        nonSelectedText: 'None selected',
                        nSelectedText: 'selected',
                        allSelectedText: 'All selected',
                        numberDisplayed: 3,
                        disableIfEmpty: false,
                        delimiter: ', ',
                        templates: {
                            button: '<button type="button" class="multiselect dropdown-toggle" data-toggle="dropdown"><span class="multiselect-selected-text"></span> <b class="caret"></b></button>',
                            ul: '<ul class="multiselect-container dropdown-menu scrollBar"></ul>',
                            filter: '<li class="multiselect-item filter"><div class="input-group"><span class="input-group-addon"><i class="glyphicon glyphicon-search"></i></span><input class="form-control multiselect-search" type="text"></div></li>',
                            filterClearBtn: '<span class="input-group-btn"><button class="btn btn-default multiselect-clear-filter" type="button"><i class="glyphicon glyphicon-remove-circle"></i></button></span>',
                            li: '<li><a tabindex="0"><label></label></a></li>',
                            divider: '<li class="multiselect-item divider"></li>',
                            liGroup: '<li class="multiselect-item multiselect-group"><label></label></li>'
                        }
                    });
                   
                });
     
     
            </script>

        </body>
    </html>
</apex:page>

Screenshot  

Comments

  1. I am following You. You are doing Good job bro. Appreciated !!!!

    ReplyDelete
  2. !!He is too good.

    ReplyDelete
  3. The common rule right here is that the more on line casino video games, the better. However, let’s be trustworthy – when you select a on line casino that provides thousands of actual money video games to check out at no cost, you won’t actually undergo all of them. It might even be a drawback because of the paradox 퍼스트카지노 of selection. Aside from free and actual money on line casino video games, Ignition additionally features virtual sports and reside supplier video games. Bovada has almost 200 on line casino video games find a way to|you possibly can} play, and over half of them are slot machines.

    ReplyDelete

Post a Comment

Popular posts from this blog

Service Cloud for Lightning Experience - All Steps Q&A [Salesforce][Trailhead]

Salesforce Process Builder in Brief (Learning/Interview)

Cloud Computing

Copado Winter 21 Administrator Maintenance Dumps

Einstein Analytics Data Preparation Specialist