function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
hgolovhgolov 

Filter Picklist Values for Opportunity Stage By SalesProcess (BusinessProcess)

Hi All,

Thank you for taking the time to read my question.

 

I have a salesprocess for my opportunity stage values. I have the businessprocess id, and can query it via the api. However, I can not find a way to filter the picklist values for return to a visualforce page to return only those that are part of the business process.

I have seen lots of questions on the forums related to this, but NOT ONE has a satisfactory answer. The businessprocess object DOES NOT return picklist values, nor does it look like it should. There was one post about the metadata, but that seems to be a different api that I can't access via my custom controller.

 

Can anyone help?

Thank you!

Best Answer chosen by Admin (Salesforce Developers) 
hgolovhgolov

I found a work-around - I created a temp opportunity for my visual force page with the correct record type, and that displayed the correct values in the drop down.

Thanks again for your time.

All Answers

*werewolf**werewolf*

Well picklist values are generally only filtered according to record types.  Do your sales processes map to record types?

*werewolf**werewolf*

Oh right, but the Process things are kind of the precursors to record type.  Business Process does have a child relationship to record type though...

hgolovhgolov

Thanks for your time. What I'm trying to do is to get picklist values via a getDescribe and then getPicklistValues() - do you know of any way to filter what gets returned in this scenario?

My current code:

 

public List<SelectOption> getStageValues(){
    Schema.DescribeFieldResult f = Opportunity.StageName.getDescribe();
        List<Schema.PicklistEntry> p = f.getPicklistValues();
           for(Schema.PicklistEntry e:p){
            myList.add(new SelectOption(e.getLabel(),e.getValue()));
        }
        return myList;
    }

 

I also tried the following:

BusinessProcess bp = [select TableEnumOrId FROM businessprocess where ID = 'XXXXXXXXXX'];
        System.debug(bp.TableEnumOrId);


and it retrieves the correct businessProcess.

 

Any idea on how to combine the two somehow?

 

Thanks!      

hgolovhgolov

I found a work-around - I created a temp opportunity for my visual force page with the correct record type, and that displayed the correct values in the drop down.

Thanks again for your time.

This was selected as the best answer
e.lestradee.lestrade

As stated in a similar thread, I've submitted an idea about this point: https://sites.secure.force.com/success/ideaView?id=08730000000bhbwAAA

 

Vote for it!

mahesh.sidhu58@gmail.commahesh.sidhu58@gmail.com

Hi Guys,

Did you able to solve this issue. If yes can you please let me know the work around. I am stuck at this point right now. Any help would be greately appreciated.

Thank you
Mahesh S
www.diligentitlabs.com

gbluesgblues

Hello from the future :)

The solution to this problem is to use a different describe method to get the PicklistEntry array.

describeSObject() gives you all of the picklist entries that exist, regardless of whether they are appropriate for your layout.

Instead, use describeLayout():

  1. invoke describeLayout() (if you have specific RecordTypes that you care about, you can pass them to describeLayout. Send null if you do not have a specific named layout defined in your backend)
  2. in the DescribeLayoutResult object, the recordTypeMappings property holds an array of RecordTypeMapping objects
  3. Each RecordTypeMapping has an array of PicklistForRecordType objects,
  4. And each PicklistForRecordType object consists of a picklistName (which corresponds to Field.name in the describeSObject hierarchy) and a PicklistEntry array. This array will only contain the PicklistEntry objects relevant for the current view.
TLDR: describeLayout() gets metadata filtered for your business process; describeSObject() does not.
Jorge EsparzaJorge Esparza
Hi @gblues from farther in the future,,

What you propose is not a solution for the problem in this thread. describeLayout is a SOAP API ( https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_calls_describelayout.htm ). And therefore not accessible via apex. Theoretically you can probably use some sort of call to MDAPI to try and get the results for that method, but then is just easier to use UI API to get the same in a less complicated manner (https://developer.salesforce.com/docs/atlas.en-us.uiapi.meta/uiapi/ui_api_resources_picklist_values.htm). 

I leave this here for anyone else who thought about using this method in their apex code to try and get picklist values. Save yourselves the research, is not as easy as it sounds. If you are using JAVA or C# this should help you in your endeavor.

JE