Activity Forums Salesforce® Discussions What is a dependent picklist in Salesforce?

  • shariq

    Member
    September 30, 2018 at 10:44 pm

    Dependent Picklist allows to contain multiple values and pick value one among them or Multiple values among them. Dependent fields depends upon controlling field.

  • Prachi

    Member
    October 3, 2018 at 12:18 pm

    hi,

    Dependent picklist is very useful within the Salesforce CRM for many reasons.  It is used to limit the list of values in one picklist based on the value of another picklist.Dependent Picklist allows to contain multiple values and pick value one among them or Multiple values among them. Dependent fields depends upon controlling field.

    thanks

  • Anjali

    Member
    October 3, 2018 at 1:35 pm

    Hi,

    Dependent picklists in Salesforce are very useful. They are used to limit the list of values in one picklist based on the value of another picklist.

    An example would be if you had a list of countries and states/provinces . If you select a country you would want the list of states/provinces to be filtered in the next picklist.

    Visualforce page

    <apex:page controller="DependentPicklistExpClass">
        <apex:form>
            <apex:pageblock>
                <apex:pageblocksection columns="2">
                    <apex:pageblocksectionitem>
                        <apex:outputlabel value="Country">
                        </apex:outputlabel>
                    </apex:pageblocksectionitem>
                    <apex:pageblocksectionitem>
                        <apex:selectlist size="1" value="{!country}">
                            <apex:selectoptions value="{!countries}"></apex:selectoptions>
                            <apex:actionsupport event="onchange" rerender="a"></apex:actionsupport>
                        </apex:selectlist>
                    </apex:pageblocksectionitem>
                    <apex:pageblocksectionitem>
                        <apex:outputlabel value="State"></apex:outputlabel>
                    </apex:pageblocksectionitem>
                    <apex:pageblocksectionitem>
                        <apex:selectlist size="1" value="{!state}" id="a">
                            <apex:selectoptions value="{!states}"></apex:selectoptions>
                        </apex:selectlist>
                    </apex:pageblocksectionitem>
                </apex:pageblocksection>
            </apex:pageblock>
        </apex:form>
    </apex:page>

    Apex Class

    public class DependentPicklistExpClass {
        public String country{get;set;}
        public String state{get;set;}
        public List getCountries()
        {
            list options=new list();
            options.add(new SelectOption('none','countries'));
            options.add(new SelectOption('US','United States'));
            options.add(new SelectOption('IN','India'));
            return options;
        }
        public list getStates()
        {
            list options=new list();
            if(country=='US')
            {
                options.add(new SelectOption('none','states'));
                options.add(new SelectOption('st1','State1'));
                options.add(new SelectOption('st2','State2'));
            }
            else if(country=='IN')
            {
                options.add(new SelectOption('none','states'));
                options.add(new SelectOption('UP','Uttar Pradesh'));
                options.add(new SelectOption('UK','Uttarakhand'));
            }
            else
            {
                options.add(new SelectOption('none','states'));
            }
            return options;
        }
    }
  • Anjali

    Member
    October 3, 2018 at 1:37 pm

    Hi,

    The Dependent Picklist Field type is a special type of single-select picklist that displays different available values depending on the current selection in another (main) picklist.

    • This reply was modified 5 years, 6 months ago by  Anjali.
  • Divya

    Member
    October 25, 2018 at 3:39 pm

    Hi Manpreet,

    A dependent picklist is a custom or multi-select picklist for which the valid values depend on the value of another field, called the controlling field. Controlling fields can be any picklist or checkbox field on the same record.

  • William

    Member
    October 29, 2018 at 5:19 am

    A Dependent picklist helps the user in adding consistent and accurate data. The valid values in dependent picklist are generally dependable on values of other fields and this is called the Controlling field. The controlling field could be any picklist not more than 300 values on the same record. The other name for the dependent picklist is the custom picklist that can be defined for Opportunities whose valid values will surely depend on some other field.

Log In to reply.

Popular Salesforce Blogs