function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
sohamsoham 

dependent picklist

i have an unique scenario

 

i have three picklist fields 

 

a) comp1-pickilst values (A , B , C , D , E , F )

b) comp2- picklist values (A, B , C , D , E , F)

c) comp3-multiselect values (A, B , C , D , E , F)

 

if i select the value A in comp1, i just want (B , C , D , E , F) to appear as option for comp2

similarly , if i select A in comp1 and and c in comp2 , i want the available picklist for the comp3 to be (B,D,E,F)

 

what should i do to implemnet this logic . i thought of dependent picklist but i dont know how to make a third field dependent on the value of two prior fields . hope i am making my case clear 

 

 

 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
hisrinuhisrinu

Hi Soham,

 

You can do this using "actionsupport" and  "rerender". The sample code is as follows.

 

Page Code:

 

<apex:page controller="TestPicklist"> <apex:form > <apex:selectList id="selectlist1" value="{!select1}" size="1"> <apex:actionSupport event="onclick" reRender="selectlist2"/> <apex:selectOptions value="{!items1}"/> </apex:selectList> <apex:selectList id="selectlist2" value="{!select2}" size="1"> <apex:actionSupport event="onclick" reRender="selectlist3"/> <apex:selectOptions value="{!items2}"/> </apex:selectList> <apex:selectList id="selectlist3" value="{!select3}" size="1"> <apex:selectOptions value="{!items3}"/> </apex:selectList> </apex:form> </apex:page>

 

 Controller Code is:

 

 

public class TestPicklist { public List<SelectOption> getItems1() { List<SelectOption> options = new List<SelectOption>(); List<Account> accList = [select name from account limit 10]; for(account a : accList) options.add(new SelectOption(a.Name,a.Name)); return options; } Public string select1{get; set;} Public string select2{get; set;} Public string select3{get; set;} public List<SelectOption> getItems2() { List<SelectOption> options = new List<SelectOption>(); List<Account> accList = [select name from account where name != :select1 limit 10]; for(account a : accList) options.add(new SelectOption(a.Name,a.Name)); return options; } public List<SelectOption> getItems3() { List<SelectOption> options = new List<SelectOption>(); List<Account> accList = [select name from account where name != :select1 and name != :select2 limit 10]; for(account a : accList) options.add(new SelectOption(a.Name,a.Name)); return options; } }

 

 

 

 

 

All Answers

Edwin VijayEdwin Vijay

Dependent picklists will work for only two levels.. third level dependency is not possible

 

 

Why not try developing using Visualforce? I can help you out

hisrinuhisrinu

Hi Soham,

 

You can do this using "actionsupport" and  "rerender". The sample code is as follows.

 

Page Code:

 

<apex:page controller="TestPicklist"> <apex:form > <apex:selectList id="selectlist1" value="{!select1}" size="1"> <apex:actionSupport event="onclick" reRender="selectlist2"/> <apex:selectOptions value="{!items1}"/> </apex:selectList> <apex:selectList id="selectlist2" value="{!select2}" size="1"> <apex:actionSupport event="onclick" reRender="selectlist3"/> <apex:selectOptions value="{!items2}"/> </apex:selectList> <apex:selectList id="selectlist3" value="{!select3}" size="1"> <apex:selectOptions value="{!items3}"/> </apex:selectList> </apex:form> </apex:page>

 

 Controller Code is:

 

 

public class TestPicklist { public List<SelectOption> getItems1() { List<SelectOption> options = new List<SelectOption>(); List<Account> accList = [select name from account limit 10]; for(account a : accList) options.add(new SelectOption(a.Name,a.Name)); return options; } Public string select1{get; set;} Public string select2{get; set;} Public string select3{get; set;} public List<SelectOption> getItems2() { List<SelectOption> options = new List<SelectOption>(); List<Account> accList = [select name from account where name != :select1 limit 10]; for(account a : accList) options.add(new SelectOption(a.Name,a.Name)); return options; } public List<SelectOption> getItems3() { List<SelectOption> options = new List<SelectOption>(); List<Account> accList = [select name from account where name != :select1 and name != :select2 limit 10]; for(account a : accList) options.add(new SelectOption(a.Name,a.Name)); return options; } }

 

 

 

 

 

This was selected as the best answer
sohamsoham
great
HareHare

Dynamic dependent pick list using apex :
 i created one Location__c object in that i Created two Pick Lists Country__c and State__c in Country__c pick list
i added India,pakistan valus and in state__c pick list i added Andrapradesh,Madhyapradesh,lohore,Quetta
if i select a value as India from Country__c pick list in State__c only able to see Andrapradesh,Madhyapradesh
if i select a value as pakistan from country_c picklist in state__c only able to see lohore,Quetta by using apex