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
Ron-LONRon-LON 

SOQL "not like" query

Hi All, 

 

 

Given a status field with values like "cancelled", "pending cancellation" , ... etc

 

I want to write this:

 

Subscription__c[] activeSubs = [select id from subscription__c where status__c not like '%cancel%'];

 

This doesn't work in real life and I'm sure Salesforce.com have some kind of reason for excluding such syntax from SOQL.

 

So does anyone have any suggestions for this other than rewriting my code every time a new status is added?

 

Thanks

Best Answer chosen by Admin (Salesforce Developers) 
milind_devmilind_dev

have u tried this.. 

 

Subscription__c[] activeSubs = [select id from subscription__c where (Not  status__c like 'cancel%'];

All Answers

milind_devmilind_dev

have u tried this.. 

 

Subscription__c[] activeSubs = [select id from subscription__c where (Not  status__c like 'cancel%'];

This was selected as the best answer
APathakAPathak

Subscription__c[] activeSubs = [select id from subscription__c where NOT (status__c  like 'cancel' )];