• Arjun Ghosh 9
  • NEWBIE
  • 5 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 3
    Replies
Hi all, I would link to make Lightning Component using in Opportunity page. In this component contains 3 picklists which its value from custom object and dependent ex. Picklist 2 depend on Picklist 1, Picklist 3 depend on Picklist 2. I have some code in Apex/VF below, How can I transform to Lighning component? Thank you in advance:

------------------- APEX -----------------------------
public class MultiSelectController {

    // reference for the standard controller
    private ApexPages.StandardController controller {get; set;}

    // the record that is being edited
    private Opportunity opp;

    // the values of the selected items
    public string selectedLevel1 {get; set;}
    public string selectedLevel2 {get; set;}
    public string selectedLevel3 {get; set;}

    public List<selectOption> level1Items {
        get {
            List<selectOption> options = new List<selectOption>();

                options.add(new SelectOption('','-- Choose a Category --'));
                for (Cat1__c cat : [select Id, Name from Cat1__c Order By Name])
                    options.add(new SelectOption(cat.Id,cat.Name));

            return options;           
        }
        set;
    }

    public List<selectOption> level2Items {
        get {
            List<selectOption> options = new List<selectOption>();

            if (selectedLevel1 != NULL) {
                options.add(new SelectOption('','-- Choose a Category --'));
                for (Cat2__c cat : [select Id, Name from Cat2__c Where Cat1__c = :selectedLevel1 Order By Name])
                    options.add(new SelectOption(cat.Id,cat.Name));
            }

            return options;           
        }
        set;
    }   

    public List<selectOption> level3Items {
        get {
            List<selectOption> options = new List<selectOption>();

            if (selectedLevel2 != NULL) {
                options.add(new SelectOption('','-- Choose a Category --'));
                for (Cat3__c cat : [select Id, Name from Cat3__c Where Cat2__c = :selectedLevel2 Order By Name])
                    options.add(new SelectOption(cat.Id,cat.Name));
            }

            return options;           
        }
        set;
    }       

    public MultiSelectController(ApexPages.StandardController controller) {

        //initialize the stanrdard controller
        this.controller = controller;
        // load the record
        this.opp = (Opportunity)controller.getRecord();

        // preselect the current values for the record
        selectedLevel1 = opp.Cat1__c;
        selectedLevel2 = opp.Cat2__c;
        selectedLevel3 = opp.Cat3__c;

    }          

    public PageReference save() {

        // set the selected values to the record before saving
        opp.Cat1__c = selectedLevel1;
        opp.Cat2__c = selectedLevel2;
        opp.Cat3__c = selectedLevel3;

        try {
            upsert(opp);
        } catch(System.DMLException e) {
            ApexPages.addMessages(e);
            return null;
        }
        return (new ApexPages.StandardController(opp)).view();
    }        

}

-------------------------- VF ----------------------------------------------
<apex:page standardController="Opportunity" extensions="MultiSelectController">  
     <apex:sectionHeader title="Opportunity" subtitle="{!opportunity.name}"/>
        <apex:form >
            <apex:pageBlock title="Opportunity" mode="edit">
                <apex:outputText value="{!opportunity.Cat1__c}" rendered="false"/>
                <apex:outputText value="{!opportunity.Cat2__c}" rendered="false"/>
                <apex:outputText value="{!opportunity.Cat3__c}" rendered="false"/>

          <apex:pageBlockButtons location="both">
               <apex:commandButton value="Save" action="{!save}" />
               <apex:commandButton value="Cancel" action="{!cancel}" />
          </apex:pageBlockButtons>
          <apex:pageMessages />       

          <apex:pageBlockSection title="Master Categories" columns="1">

                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="Category 1" for="cbxlevel1"/>
                    <apex:outputPanel styleClass="requiredInput" layout="block">
                    <apex:outputPanel styleClass="requiredBlock" layout="block"/>
                    <apex:selectList value="{!selectedLevel1}" id="cbxlevel1" size="1" required="true">
                        <apex:selectOptions value="{!level1items}"/>
                        <apex:actionSupport event="onchange" rerender="cbxlevel2"/>
                    </apex:selectList>
                    </apex:outputPanel>
                </apex:pageBlockSectionItem>

                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="Category 2" for="cbxlevel2"/>
                    <apex:selectList value="{!selectedLevel2}" id="cbxlevel2" size="1">
                        <apex:selectOptions value="{!level2items}"/>
                        <apex:actionSupport event="onchange" rerender="cbxlevel3"/>
                    </apex:selectList>
                </apex:pageBlockSectionItem>

                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="Category 3" for="cbxlevel3"/>
                    <apex:selectList value="{!selectedLevel3}" id="cbxlevel3" size="1">
                        <apex:selectOptions value="{!level3items}"/>
                    </apex:selectList>
                </apex:pageBlockSectionItem>

          </apex:pageBlockSection>

     </apex:pageBlock>
     </apex:form>   

</apex:page> 
Hi all,

I have an custom object named country with two picklist fields country and states.  Country is the controlling field for States.  Now I want to display these two picklist in the lightning page with the controlling and dependent picklist behavior.  Kindly let me know how I can achieve this.

Thanks in advance

Regards

V Swathi
Hi, 

How to get sObject's dependent picklist in lightning component.
I have tried through <force:inputfield> but no luck.

Thanks,
Anupama