Stack Exchange network consists of 183 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It only takes a minute to sign up.
I wrote below query for single status check, it is working but not for multiple status checks, it is throwing errors.
String draft = 'Draft';
String cancel = 'Cancelled';
String cmpnQuery = 'SELECT ID,Name,FROM Campaign where status!=:draft'; //working without issues
String campQuery = 'SELECT ID,Name FROM Campaign where status NOT IN (draft,cancel)'; // not working
for(Campaign cmpn:Database.Query(cmpnQuery )){
//TO- DO
}
What error(s) are you getting? Please edit your question to include them. It could be that you simply need to add some (escaped) quotes around your target status values in the second query string.
draft,cancel are string values so use a list and bind that here in the same way you did in last query Set<String> discardStatuses = new Set<String>{'draft', 'cancel'} and use it like 'SELECT ID,Name FROM Campaign where status NOT IN :discardStatuses
By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.
Set<String> discardStatuses = new Set<String>{'draft', 'cancel'}
and use it like'SELECT ID,Name FROM Campaign where status NOT IN :discardStatuses