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
Prerna BhallaPrerna Bhalla 

Dependenent values upto 2 level

Heyy i am in thus situtation that i have 3 picklist picklist 1 picklist 2 and picklist 3 . Picklist 1 is controlling list for picklist 2 and picklist 2 is controlling field for picklist 3. Now i am able to fetch the picklist 2 dependent values based on picklist 1 controlling value. But problem is that on the basis of picklist 2 selectrd value i have to fetch picklist 3 depent values. The same function who return me picklist 2 depent value not returning picklist 3 dependent value for conttolling value from picklist 2. Help me i am stuck in this situation. I am using same above code for dependentency upto 2 1 level showing me correct dependent values but at third level i am not getting any result. Suppose i select fruit dependent value is green colr fruit and yellow color fruit i choose yellow option should show me banana mango like that
Prateek Singh SengarPrateek Singh Sengar
Your apex should look something like this.
public with sharing class MyController {
    public string firstPick { get; set; }
    public string secondPick { get; set; }
    public string thirdPick { get; set; }

    public MyController() {
        firstPick = secondPick = thirdPick = null;
    }
    
    public List<SelectOption> getListFirst() {
        List<SelectOption> options = new List<SelectOption> { new SelectOption('','-- Choose --') };
        
		for(YOUR LOOP TO ADD PICK VALUES) 
		{
            options.add(new SelectOption(PICK_VAL,PICK_LABEL));
        }
        return options;
    }
    
	public List<SelectOption> getListSecond() {
        List<SelectOption> options = new List<SelectOption>(); 
        if(firstPick == null || firstPick == '')
		{
			return options;
		}
		else
		{
			//condition based on first pick value
			for(YOUR LOOP TO ADD PICK VALUES) 
			{
				options.add(new SelectOption(PICK_VAL,PICK_LABEL));
			}
			return options;
		}
		
		
    }
	
	public List<SelectOption> getListThird() {
        List<SelectOption> options = new List<SelectOption>();
		if(secondPick == null || secondPick == '')
		{
			return options;
		}
        else
		{
			//condition based on second pick value
			for(YOUR LOOP TO ADD PICK VALUES) 
			{
				options.add(new SelectOption(PICK_VAL,PICK_LABEL));
			}
			return options;
		}
    }
	
}

your visualforce should be something like
 
<apex:page controller="MyController">
    <apex:form id="theForm">
        <apex:sectionHeader title="Choose First Value"/>
        <apex:pageBlock title="">
            <apex:pageBlockSection columns="1">
                <apex:pageBlockSectionItem >
                    <apex:outputLabel >First Picklist</apex:outputLabel>
                    <apex:selectList size="1" multiselect="false" value="{!firstPick}">
                        <apex:selectOptions value="{!listFirst}"/>
                        <apex:actionSupport reRender="theForm" event="onchange"/>
                    </apex:selectList>
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >
                    <apex:outputLabel >Second Picklist</apex:outputLabel>
                    <apex:selectList value="{!secondPick}" size="1" multiselect="false">
                        <apex:selectOptions value="{!listSecond}"/>
                        <apex:actionSupport reRender="theForm" event="onchange"/>
                    </apex:selectList>
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem>
                    <apex:outputLabel >Third Picklist</apex:outputLabel>
                    <apex:selectList value="{!thirdPick}" size="1" multiselect="false">
                        <apex:selectOptions value="{!listthird}"/>
                        <apex:actionSupport reRender="theForm" event="onchange"/>
                    </apex:selectList>
                </apex:pageBlockSectionItem>
			</apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>

Please note that this page uses action support to render the values