Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to describe (enumerate) picklist enties valid for a specific record type in Salesforce?

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.

like image 549
David Avatar asked Oct 18 '11 16:10

David


People also ask

How do I create a picklist in Salesforce?

Click: Setup > Create> Objects> Section_2_Balance_Sheet_c> Record Types > then click on each of the record types you need to add the picklist value to. On the record type detail page you will find a section called Picklists Available for Editing. From that list locate your picklist field and click Edit. Add the values you need to the right column.

What are record types in Salesforce?

Record types in Salesforce allow you to have different business processes, picklist values, and page layouts to different users based on profile. You might create record types to differentiate your regular sales deals from your professional services engagements, offering different picklist values for each.

How do I create a new record type in Salesforce Lightning?

For example, for creating account record type is lightning From Setup, click Object Manager and select Account. Select Record Types, click New, and fill in the details. Page layouts control the layout and organization of buttons, fields, Visualforce, custom links, and related lists on object record pages.

What is a field dependency in Salesforce?

Field dependencies are filters that allow us to change the contents of a picklist based on the value of another field. Rather than displaying every value for Region in a single picklist, you can limit the values that are displayed based on a value for another field, like Zone.


Video Answer


2 Answers

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

I found here that one can actually get a list of record type specific picklist values by making a describeLayout() call.

Using your example (C#):

DescribeLayoutResult result = binding.describeLayout("Account", new string[] { "01230000000xxXxXXX" } );
PicklistEntry[] values = result.recordTypeMappings[0].picklistsForRecordType[12345].picklistValues;
  • Replace "01230000000xxXxXXX" with a RecordTypeId of your Retailer record type object. Use the query "SELECT Id FROM RecordType WHERE Name = 'Retailer'" to get the value.
  • Replace 12345 with an index of your picklist object that you would like to get values of.
like image 102
GritKit Avatar answered Nov 29 '22 04:11

GritKit


You can't do it in pure Apex AFAIK, unfortunately. The metadata API does expose it.

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

like image 33
jkraybill Avatar answered Nov 29 '22 05:11

jkraybill