0

I am trying to create a multiple picklist on lightning page but i am not able to fetch sObject in multiple picklist.

Here is my code :-

Controller class:-

global with sharing class AboutController{

    public List<SelectOption> sObjectSelectOptionList {get;set;} // This will replace Sobjects variable
    Public List<String> leftSelected {get;set;}
    Public List<String> rightSelected {get;set;}
    Set<String> leftValues = new Set<String>();
    Set<String> rightValues = new Set<String>();


    public AboutController(){

    sObjectSelectOptionList = getSobjects();


        leftSelected = new List<String>();
        rightSelected = new List<String>();

        **//here how to add selectOption list into set of string dont knw thts why i commented.. 
        //leftValues.addAll(sObjectSelectOptionList);**



    }

    public List < SelectOption > getSobjects() {
        List < SelectOption > options = new List < SelectOption > ();
        List<Schema.sObjectType> sobjects = new List<Schema.sObjectType>();
        sobjects = Attachment.parentid.getDescribe().getReferenceTo();
        for(Schema.SObjectType item1 : sobjects){
            if(item1.getDescribe().isAccessible()){
                options.add(new SelectOption(item1.getDescribe().getName(), item1.getDescribe().getName()));
            }
        }
        options.sort();
        return options;
    }


     public PageReference getSelect(){
        rightSelected.clear();
        for(String s : leftSelected){
            leftValues.remove(s);
            rightValues.add(s);
        }
        return null;
    }

    public PageReference getDeselect(){    
        leftSelected.clear();
        for(String s : rightSelected){
            rightValues.remove(s);
            leftValues.add(s);
        }
        return null;
    }

    public List<SelectOption> getDeselectedValues(){
        List<SelectOption> options = new List<SelectOption>();
        List<String> objList = new List<String>();
        objList.addAll(leftValues);
        objList.sort();
        for(String s : objList){
            options.add(new SelectOption(s,s));
        }
        return options;
    }

    public List<SelectOption> getSelectedValues(){

        List<SelectOption> options = new List<SelectOption>();
        List<String> objList = new List<String>();
        objList.addAll(rightvalues);
        objList.sort();
        for(String s : objList){
            options.add(new SelectOption(s,s));
        }
        return options;
    }

}

and here is my component page code :-

 <div class="slds-col slds-size_1-of-1 slds-small-size_1-of-1 slds-medium-size_1-of-1 slds-large-size_1-of-1">
                    <div class="slds-box slds-m-vertical_x-small">
                        <div class="border-bottom-brand-1x">
                            <h3 class="slds-page-header__title text-color-brand">Select Object which you want to show on Picklist</h3>
                        </div>
                       <div class="slds-form-element slds-m-around_small">
                            <apex:panelGrid columns="3" id="abcd">
                                <apex:selectList id="sel1" value="{!leftSelected}" multiselect="true" style="width:100px" size="5">
                                    <apex:selectOptions value="{!DeselectedValues}" />
                                </apex:selectList>

                                <apex:panelGroup >
                                    <br/>
                                    <apex:image styleClass="picklistArrowRight" value="/s.gif">
                                        <apex:actionSupport event="onclick" action="{!getSelect}" reRender="abcd"/>
                                    </apex:image>
                                    <br/><br/>
                                    <apex:image styleClass="picklistArrowLeft" value="/s.gif">
                                        <apex:actionSupport event="onclick" action="{!getDeselect}" reRender="abcd"/>
                                    </apex:image>
                                </apex:panelGroup>
                                <apex:selectList id="sel2" value="{!rightSelected}" multiselect="true" style="width:100px" size="5">
                                    <apex:selectOptions value="{!SelectedValues}" />
                                </apex:selectList>
                            </apex:panelGrid>

                       </div>
                        <div class="slds-form-element slds-m-around_small">
                            <apex:commandButton styleClass="slds-button slds-button_brand btnSubmit" value="Save"  status="status"/> 
                        </div>
                    </div>

                </div>

please help me out where i did mistake thats why i am not able show sobject in picklist.

  • You currently have a VF page and its controller code in here. Is there a lightning component that you are trying to build? – Jayant Das Dec 28 '18 at 6:05
  • no, its just a page where i used slds. problem not in design. problem is i just want to show sobject into that picklist. i know i did some mistake in controller class can you please figure out with solution. – Hennry Dec 28 '18 at 6:13
  • Okay so you should then edit your question title and tags as you are only using SLDS here for UX but you are still building a VF page. – Jayant Das Dec 28 '18 at 6:15
0

You seem to be populating your SObject picklist on the VF page with this code:

<apex:selectList id="sel1" value="{!leftSelected}" multiselect="true" style="width:100px" size="5">
    <apex:selectOptions value="{!DeselectedValues}" />
</apex:selectList>

The values will be rendered based on what the method getDeselectedValues() in your controller class returns.

Taking a look at the method in your controller class, you seem to be returning an empty list of select options and thus you do not get any output on the VF page.

Changing the method to one as below should work.

public List<SelectOption> getDeselectedValues() {
// because you already have the list of options populated in getSobjects(), just return that
    return getSobjects();
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.