Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Salesforce by (11.9k points)

In apex code I want to enumerate the legal values for a picklist field. To do this I can just call Account.Foobar__c.getDescribe().getPickListValues() and I've got a list of Schema.PickListEntry values.

However it's possible to setup multiple record types for a given sObject. For example Account might have "Manufacturer", "Distributor" and "Retailer" record types. In the Salesforce setup it is possible edit (limit) the picklist entries for each field based on record type. So Retailer type accounts might only use a subset of the picklist values for the Foobar field.

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

1 Answer

0 votes
by (32.1k points)
edited by

Using your example,

DescribeLayoutResult result = binding.describeLayout("Account", new string[] { "01230000000xxXxXXX" } );

PicklistEntry[] values = result.recordTypeMappings[0].picklistsForRecordType[12345].picklistValues;

  • Use the query "SELECT Id FROM RecordType WHERE Name = 'Retailer'" to get the value.

Want to learn Salesforce from the scratch? Here's is the right video for you on Salesforce provided by Intellipaat:

  • Replace the indexer [12345], which isn't consistent between calls. You could use a LINQ expression to go by the picklist Name Like:

picklistsForRecordType.SingleOrDefault(pl=>"Retailer".Equals(pl.picklistName).picklistValues

To learn in-depth about Workflow in Salesforce, sign up for an industry based Salesforce Admin Certification.

Browse Categories

...