Salesforce: Get List of “Closed” Opportunity Stages
-
26-02-2021 - |
Question
In Apex, I need to get a list of the Opportunity stages that are closed. These are stages that, in setup, are of the type "Closed/Won" or "Closed/Lost".
I can get a list of stage names using:
Opportunity.StageName.getDescribe().getPicklistValues()
This returns a List of Schema.PicklistEntry
objects, but they do not indicate the type of stage.
La solution
For that you will have to query the OpportunityStage table, it has fields that flag isWon & isClosed (amongst other things) for each option.
Such a query would look like this:
[SELECT Id, ApiName FROM OpportunityStage WHERE IsWon = true AND IsClosed = true]
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow