Find your content:

Search form

You are here

How can we write dependent picklist through apex code?


2 picklists are there State(controlling filed) and City(dependent field). in state picklist AP,KA,TN is there. By selecting AP state, Hyd,Nlg,Wrngl should be available in City picklist. By selecting TN state, Chennai, Salem, Vellor should be available in City picklist. By selecting KA state, Manglore, Mysore, Hampi should be available in City picklist.

Attribution to: sri

Possible Suggestion/Solution #1

This functionality has been there since API 19.0 so you don't really need to write any code for this.

If you still have a use case which warrants handling the dependent picklist behavior through your Apex code, I'd recommend you go through this tutorial on how to do so.

I hope this helps.

Attribution to: Gaurav Kheterpal

Possible Suggestion/Solution #2

Since this is an OOTB available feature, all you would need to do is use apex:inputField on your visualforce page and make sure you have made the picklists dependent. Using apex:inputField will bind all the validations and dependencies related to the specified field, so you need not write any code for this.

Attribution to: Vishal
This content is remixed from stackoverflow or stackexchange. Please visit

My Block Status

My Block Content