Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Salesforce: Get List of "Closed" Opportunity Stages

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.

like image 858
Jeremy Ross Avatar asked Oct 29 '25 16:10

Jeremy Ross


1 Answers

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]
like image 85
superfell Avatar answered Oct 31 '25 05:10

superfell



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!