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
Jina ChetiaJina Chetia 

How to make dependent picklist work in VisualForce page?


I have a Contract Terms Custom Object which has a dependent picklist named 'Territory' depending on 'Region' picklist. I have used these two picklist in my page using the inputField tag but I am not getting the behaviour of the depending picklist. As soon as I change the Region value, the Territory picklist values should change depending on the value selected but it does not happen.

Here is the piece of code
        <apex:pageBlock title="Section 2" rendered="{!showSecondSection}">
            <p>To what geography does this rate apply— </p>
             Region: <span style="padding:10px;"/>
             <apex:inputField value="{!contractTerms.REGION__c}"></apex:inputField>
             <p> Territory: <span style="padding:10px;"/>
             <apex:inputField id="territory" value="{!contractTerms.TERRITORY__c}"/></p>
             <p><span style="padding:10px;"/><apex:commandButton action="{!showSection3}" 
value="Continue" styleClass="btn"></apex:commandButton></p><br/> </apex:pageBlock>

Can anyone please help me resolve this issue?

Dependent picklists are not yet supported by inputfield out of the box. Hopefully they will be in one of the future releases.
Until then, if you want the dependency logic I think you'll have to build it yourself by using events (onBlur etc.) on inputfield in tandom with components like apex : actionSupport
Is there any news on the dependent picklists? Are these going to be included in some future release?
I have same problem, did you solve it?

I create 2 custom picklist field (A and B), B's value depends on A.

I wrot ajax and apex to set B's value when A changes. In sf I set B as {1,2,3} when A is 1. set B {2,3,4} when A is 2.

But I can not find the apex api to select dependency relation between A and B. I want to write code like below.
Select values from B where B.dependencyvalue = A.value.

do you know how to select the dependency relation between A and B?

do you know how to select the dependency relation between A and B with Apex code?

my post it as below:

Surely there is a database table which stores the relationship between the picklist fields? Which can then be used in the apex to recreate this relationship. Does anyone know about this?
Please, anyone has a solution?

most of us are not looking for a javascript solution, but rather an Apex solution, run on platform, and completely compliant with on platform dependencies.


is there a way to access this information in Apex or not?


furthermore, what is the point of the isDependentPicklist() method of Field Describe Result if you really can't do anything but confim, yes, this is a dependent picklist.


The solution here is to extend getPicklistValues() to accept a param, which is the selected value of the controlling field.  Are you listening Salesforce?


I was able to successfully implement Richard's solution, however when i hit save I receive a validation error message "Value is not valid"


I get this error on the dependentField! 


Any idea why?


Sam.arj wrote:

I was able to successfully implement Richard's solution, however when i hit save I receive a validation error message "Value is not valid"


I get this error on the dependentField! 


Any idea why?

Sam, were you able to Resolve your error? I'm facing the same error.


OMG... you have to be kidding me... :( 

This is horribly frustrating. 


I got Richard's code to work properly (after fighting the "Value is not valid" validation errors).  The dependent pick lists must be populated from a VisualForce controller first.  See my solution here:


As a side note, please vote up this idea on idea exchange, so we don't have to implement silly workarounds: 

Message Edited by babbott on 02-05-2010 05:58 PM

Message Edited by babbott on 02-05-2010 06:00 PM

Have you guys looked at this article:



It looks pretty straightforward, a VF controller and an <actionSupport> tag.


Rich C.

Yes, the "dependent picklists - plus" solution would work, however, if you already have SF objects setup a certain way with dependencies, you would have to make a lot of changes to achieve this goal (i.e. creating new objects with dependencies between them, etc...).

Hi Babbott,


I have read ur blog and followed ur steps. but it doesnt work.


I am not sure what the last parameter -- initialValues should be for function DependentPicklistHelper().


Could you give me an example?


Can it be set to ''?


Many thanks,




In case anyone else stumbles across this thread, pretty sure VF now supports this:


It is still not working properly.   If the value of the controlling field is changed in the controller, the dependent picklist is not trimmed down to specific values, but is displaying all of the values available.  


This is the case when the VF page is only displaying the dependent picklist, and is not displaying the controlling field.   If both fields are displayed on the page, then the dependency is working correctly.



That is true, both controlling and dependent fields need to be in page then it works ok.

Workaround to have only the dependent field shown is to modify the page DOM with own javascript.