How to get list of dependent picklist options in apex?

How to get list of dependent picklist options in apex?

One method, self-contained, about 30 lines of code. The method returns a map of lists, keyed by controlling values, the lists contain all valid dependent values for the controlling value. This works when the controlling field is a checkbox (boolean) as well as a picklist.

What does dependent picklist mean in Salesforce help?

Salesforce supports the concept of a “dependent” picklist, that is, a picklist whose values vary based on the state of another field (the “controlling” field). According to Salesforce Help: A dependent picklist is a custom or multi-select picklist for which the valid values depend on the value of another field, called the controlling field.

How is the schema.picklistentry deserialized in apex?

The Schema.PicklistEntry is serialized and deserialized using the Apex JSON class. By using JSON.deserializeUntyped, we avoid the need to declare a class to use when deserializing, and the code will continue to work even if Salesforce changes the internals of the Schema.PicklistEntry class — as long as it continues to have a validFor field.

What happens to controlvalue when picklist is inactive?

If the controlling field is a picklist, then controlValue will be assigned the label of the active picklist value, or null, if the picklist value is inactive. If the controlling field is a checkbox, then controlValue will be assigned false (when index is 0) or true (when index is 1).

What is the validfor member of picklistentry object?

When obtained from the API, the PicklistEntry object contains a member, called validFor, that encodes the information we seek. Some very clever people discovered long ago that the Apex Schema.PicklistEntry object also contains this member, even though there is no method to return its value.