All I want to do is return Opportunities where the stage name is not equal to Closed Won or Closed Lost. I am sure this is simple, but I do not know the correct format.

enter image description here

  • 1
  • 1
    Thank you all for the help. Since I am doing this in Dev Console I will use Nihir suggestion this time. However, both are great answers. Thanks again! Jul 19, 2017 at 13:33
  • 2
    For reference, you can use IN with literal values, ie SELECT Id FROM Account WHERE Status IN ('Open', 'Under Review') Jul 19, 2017 at 13:37
  • @CraigRowland Don't forget to mark answer as best as it useful for others
    – Nihar
    Jul 19, 2017 at 13:38
  • Or in this case: NOT IN ('Closed Won', 'Closed Lost')
    – Charles T
    Jul 19, 2017 at 13:51

3 Answers 3


Totally agree with Rohit's answer for Apex but You can use this soql in developer console :

Select Id, Name from Opportunity where stageName != 'Closed Won' AND stageName != 'Closed Lost'
  • 1
    OR isn't correct, because it would still query all opportunities.
    – sfdcfox
    Jul 19, 2017 at 13:44
  • @sfdcfox thanks for marking, i will take care of it next time :)
    – Nihar
    Jul 19, 2017 at 13:46
  • 1
    Yeah this would need to be an AND.
    – Charles T
    Jul 19, 2017 at 13:50

You can use NOT IN to filter by multiple values:

select id from opportunity where stagename not in ('a','b')

Use IN keyword. Refer below example:

List<String> lst = new List<String>();
lst.add('Closed Won');

List<Opportunity> opList = [SELECT Id FROM Opportunity Where StageName NOT IN :lst];

You must log in to answer this question.

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