Activity › Forums › Salesforce® Discussions › What is a dependent picklist in Salesforce?
Tagged: Apex Class, Apex Code, Dependent Field, Dependent Picklist, Picklist Field Value, Picklist Values, Salesforce Code, Salesforce CRM, Visualforce Page
-
What is a dependent picklist in Salesforce?
Posted by Manpreet on September 30, 2018 at 10:44 PMWhat is a dependent picklist in Salesforce?
William replied 7 years, 6 months ago 6 Members · 6 Replies -
6 Replies
-
Dependent Picklist allows to contain multiple values and pick value one among them or Multiple values among them. Dependent fields depends upon controlling field.
- [adinserter block='9']
-
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
-
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; } } -
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.
-
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.