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
Adu86Adu86 

SOQL String Query

Hi,

I am trying to write a String SOQL query in a Batch class. I need to query records with a particular condition as written below:

 String Soql = 'SELECT id,StageName FROM Opportunity Where StageName in (\'Quoted\',\'Bound\',\'Working\')' ;

Here StageName is a Picklist field . So I need to query record with above those three picklist values, but this query is not working. Please let me know how to construct a String with this "Where" condition.

Thanks


 
Best Answer chosen by Adu86
Balaji BondarBalaji Bondar
Hi Sni,

Try below code:
Set<String> stageNameSet = new Set<String> ();
stageNameSet.add('Quoted');
stageNameSet.add('Bound');
stageNameSet.add('Working');
String Soql = 'SELECT id,StageName FROM Opportunity Where StageName in :stageNameSet';
Important :
If this is what you were looking for then please mark it as a "SOLUTION" or You can Click on the "Like" Button if this was beneficial for you.