I would like to get the available stages for a specific opportunity sales process via code.
BusinessProcess and RecordType objects are not connected to the OpportunityStage object.
The code below doesn't help either (see the debug result in the code comment):

Schema.DescribeFieldResult f = Opportunity.StageName.getDescribe();
    List<Schema.PicklistEntry> p = f.getPicklistValues();
       for(Schema.PicklistEntry e:p){
        system.debug('Pick list entry: ' + e); //Pick list entry: Schema.PicklistEntry[getLabel=Target;getValue=Target;isActive=true;isDefaultValue=false;]

Do you have any suggestions?

1 Answer 1


I'm going to assume that you're trying to tie your Sales Processes in with your Business Process' RecordTypes and your Opportunity Stages so that everything is consistent and the associations are connected as originally intended.

Unfortunately, picklists cannot be selected by RecordType using Apex. That can only be done via the metadata API or using a workaround that Andrew Fawcett posted several years ago that I can't seem to locate at the moment. However, it can be found in his github repository at https://github.com/financialforcedev/apex-mdapi.

There are two other related posts that may be helpful to you. One is this Stack Overflow post with an answer involving a SOQL query: https://stackoverflow.com/questions/7810801/how-to-describe-enumerate-picklist-enties-valid-for-a-specific-record-type-in. Second is this post by @Eric that discusses the entire issue of picklists and record types along with his solution to the issues: How do I get the intersection of RecordType and Picklist values inside Apex?. Hopefully, you'll find that one of these 3 solutions will provide what you're looking for to help you reach your objective.

  • Thanks @crmprogdev for the answer. The 2 links didn't help and there isn't a link to the post by Eric. Anyway, we decided to go with custom setting on this case.
    – Dagish
    Commented May 5, 2016 at 13:34
  • My apologies for the missing link. Here it is: salesforce.stackexchange.com/questions/103837/…. In the past, I've frequently gone with custom settings myself in these situations. From your post, I thought you were trying to more easily find the relationships to begin with.
    – crmprogdev
    Commented May 5, 2016 at 13:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .