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
Taps makTaps mak 

Dynamic dependent Picklist using apex

Hi,
In my code I am getting controlling field value from another page through parameter and using this value I need to display its dependent picklist values as a textvalue on VF Page. I have used Schema.DescribeSObjectResult for getting picklist values dynamically but using this option I am getting all the values and not dependent value. How can I achieve to get dependent values.

Thanks In advance.
Łukasz BieniawskiŁukasz Bieniawski
Hi Taps,

I will try something like this, this is the simplest way:

A -> controlled picklist
B -> dependent picklist
  1. Add dependend picklist (B) to the target page and hide it from the view
  2. When controlled value is passed just set it as a value in the controlled field (A)
  3. Rerender dependend picklist area (B, hidden list from point 1) -> list should be automatically filtered by Salesforce
  4. Set your own method to be invoked on after rerender i.e. onComplete="yourJSmethod();"
  5. Read values from the hidden list (B) by using i.e. jQuery and set final value to textarea where you want it to be displayed
If you want to achieve this in the controller you have to do something like that (http://titancronus.com/blog/2014/05/01/salesforce-acquiring-dependent-picklists-in-apex/). Bear in mind that from Apex level you are not able to filter values by record types.

Hope this helps,
Lukasz