How to describe (list) a picker valid for a particular record type in Salesforce?

In apex code, I want to list the legal values ​​for the select box. To do this, I can simply call Account.Foobar__c.getDescribe().getPickListValues() , and I have a list of Schema.PickListEntry values.

However, it is possible to set several types of records for this sObject. For example, an account may have the types of entries Producer, Distributor, and Retail. In the Salesforce setting, you can edit (limit) the records of the selection list for each field, depending on the type of record. Thus, Retailer accounts can only use a subset of the selection list values ​​for the Foobar field.

So basically I want Account.Foobar__c.getDescribe().getPickListValues('Retailer') , but that is not the syntax. The validFor method looks promising, but it looks like it is only for field-dependent picklists β€” a selector filtered only by record type returns false for isDependentPicklist .

+7
source share
2 answers

You cannot do this in pure Apex AFAIK, unfortunately. The metadata API exposes it.

Related opinions: http://boards.developerforce.com/t5/Apex-Code-Development/Any-way-to-obtain-picklist-values-by-record-type/td-p/287563

+2
source

I know this is an old post, but maybe the information below will help someone who still needs an answer.

I found here that it is actually possible to get a list of record types to select a record type by creating a call to describeLayout ().

Using your example (C #):

  DescribeLayoutResult result = binding.describeLayout ("Account", new string [] {"01230000000xxXxXXX"});
 PicklistEntry [] values ​​= result.recordTypeMappings [0] .picklistsForRecordType [12345] .picklistValues;
  • Replace "01230000000xxXxXXX" with the RecordTypeId of the object of the Retailer record type. Use the query "SELECT Id FROM RecordType WHERE Name =" Retailer "to get the value.
  • Replace 12345 with the index of your picklist object that you want to receive.
+5
source

All Articles