+ Start a Discussion
arasuarasu 

Does SOQL support "NOT LIKE" operator?

Hi,
I want to write a query like this:

select Account__r.Id,Account__r.Name,Account__r.Account_Country__c from Card_UPC__c where Account__r.partner_relationship_status__c='Allow Relationships To Be Created' and Account__r.Name not like 'Test%'.
 
The above query throws SOQL exception.
 
It works and runs when I remove the NOT operator as shown below:

select Account__r.Id,Account__r.Name,Account__r.Account_Country__c from Card_UPC__c where Account__r.partner_relationship_status__c='Allow Relationships To Be Created' and Account__r.Name like 'Test%'
 
My questions is: Does SOQL support "NOT LIKE" operator. If no, then what is the alternative to achieve a similar operation.
 
Thanks for all your feedbacks.
Ambili
Best Answer chosen by Admin (Salesforce Developers) 
arasuarasu

Hi Simon,

Thanks for your response. Actually the brackets were missing. The following SOQL works fine:

select Account__r.Id,Account__r.Name,Account__r.Account_Country__c from Card_UPC__c where Account__r.partner_relationship_status__c='Allow Relationships To Be Created' and  (NOT Account__r.Name  like 'Test%').

Thanks,
Ambili

 

All Answers

SuperfellSuperfell
http://www.salesforce.com/us/developer/docs/api/index_CSH.htm#sforce_api_calls_soql_select.htm#comparison_operators

not foo__c like 'bar%'
arasuarasu

Hi Simon,

Thanks for your response. Actually the brackets were missing. The following SOQL works fine:

select Account__r.Id,Account__r.Name,Account__r.Account_Country__c from Card_UPC__c where Account__r.partner_relationship_status__c='Allow Relationships To Be Created' and  (NOT Account__r.Name  like 'Test%').

Thanks,
Ambili

 

This was selected as the best answer
hemantgarghemantgarg

I found it very useful, Thanks!

sfdcdev.wordpress.comsfdcdev.wordpress.com
Correct answer at - http://sfdcdev.wordpress.com/2013/12/26/not-like-soql-salesforce-com/
Robert JoyRobert Joy
Thank you!
Watson CarrenWatson Carren
Watson CarrenWatson Carren
Edit Video Like a Pro With KineMater (https://apkright.com/kinemaster-mod-apk/)