+ Start a Discussion
Jim BoudreauxJim Boudreaux 

Query Stage Types of Opportunities

I need to write a SOQL query that returns opportunities based on the Stage field. I could do that easily, however, it's not the name or label of the picklist value I need to filter, it's the type. The Stage field could have many different values, some of which have a Type 'Closed/Won' and I want to return opportunities with a stage of type 'Closed/Won', how would I write a Where clause for that?

Kevin SwiggumKevin Swiggum

There's an auto-populated column on the Opportunity object named "isWon" which resolved to true for any Stage Name that's configured to represent Closed/Won.


So all you need is :

List<Opportunity> oppList = [SELECT ID FROM Opportunity WHERE isWon = true];