7

I've searched high and low and can't seem to find any posts or blogs showing how to get picklist values for a particular recordType to use in a custom controller.

I can easily obtain the RecordType I need using code like this:

    Map<String, Schema.RecordTypeInfo> RT = Task.SObjectType.getDescribe().getRecordTypeInfosByName();
    //String var to of Record Type name's label to look for, note the label is used not the api name

    String RTname = 'Field Sales';
    //Id var to store desired Record Type id in 

    Id TaskRTId;

    // Below only works if the record type above exists 
    if(RT.containsKey(TaskRTId)){           
        //can add these to a list if checking for more than one in a for loop
        TaskRTId = RT.get(check).getRecordTypeId();
        SYSTEM.debug(RT.get(TaskRTId).getRecordTypeId());
    }

I can use getPicklistValues() from a describe field results to get ALL the picklist values, but not for the specific RecordType.

List<SelectOption>options = new List<SelectOption>();
Schema.DescribeFieldResult fieldResult = Task.Type.getDescribe();
List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
for( Schema.PicklistEntry f : ple)
{
    options.add(new SelectOption(f.getLabel(), f.getValue()));
}      

So, is there a means of isolating the results of the picklist values to the above RecordType via Apex?

  • 1
    I don't think there is. Here is what I resorted to for Picklist values by record type for AngularJS UI. – Keith C Nov 17 '15 at 20:38
  • @KeithC That's good work. That appeared to be the conclusion I'd come to as I've only seen references to accessing it through the metadata API. I really don't want to have to do this when I only need it for one RT that could be held in custom settings (with the rest of LOTS of related config) in an app I'm tasked with adding new functionality to. – crmprogdev Nov 17 '15 at 20:48
0

Plese go thorugh this answer https://salesforce.stackexchange.com/a/81745/5634

For any questions or doubt..ask again In linked question: zone is the record type and status and category are dynamic pick-list values based on zone type. I used page describe of JavaScript

| improve this answer | |
  • I can post the whole answer here, which is already metion in existing thread. Just described here. I don't know,what is the wrong with moderator. who made this negative answer. I understood, we should not mention the link. but dt's not always true. :( – Ankuli Aug 16 '16 at 6:32

Not the answer you're looking for? Browse other questions tagged or ask your own question.