• About
  • Contact me!

Salesforce Everywhere

~ Blog on Salesforce Dev and admin stuff

Salesforce Everywhere

Tag Archives: NOT LIKE IN SOQL

SOQL : Using NOT LIKE

01 Tuesday Sep 2015

Posted by Mani in Apex

≈ Leave a comment

Tags

NOT LIKE IN SOQL, SOQL

There may be instances where we need to use NOT LIKE in SOQL(I got to use it recently in my project) and using it in SOQL is little more counter intuitive unlike LIKE.

For instance, we want to fetch Id from Job where Status=Complete,Type contains ‘Physiotherapy’ and it should not contain ‘Pain Management’, for instance Type=’Physiotherapy Pain Management’ should not be fetched and the correct query is as follows:

select id from Job__c where Job_Status__c=’Complete’ and Type__c LIKE ‘Physiotherapy%’ and (NOT Type__c LIKE ‘%Pain Management%’)

You might get MALFORMED_QUERY … unexpected token: ‘not’ or MALFORMED_QUERY … unexpected token: ‘like’, if you try any similar variants as below which would not work:

select id from Job__c where Job_Status__c=’Complete’ and Type__c LIKE ‘Physiotherapy%’ and NOT Type__c LIKE ‘%Pain Management%’

select id from Job__c where Job_Status__c=’Complete’ and Type__c LIKE ‘Physiotherapy%’ and NOT (Type__c LIKE ‘%Pain Management%’)

select id from Job__c where Job_Status__c=’Complete’ and Type__c LIKE ‘Physiotherapy%’ and Type__c NOT LIKE ‘%Pain Management%’

Happy sharing!

Advertisement

Blog Stats

  • 114,773 hits

Archives

Recent Posts: Salesforce Everywhere

How to get field values on onLoad in lightning-record-edit-form in LWC?

Using Dynamic Actions

How to check if the logged in user is a Guest user or not in APEX class?

How to Close Quick action in LWC

Lightning component to filter Products and display results in lightning data table

Connect with me

  • View @manibalan_s’s profile on Twitter
  • LinkedIn

Developer links

  • Salesforce Developer website
  • Salesforce Success Community

Enter your email address and click on Follow us (below) to follow this blog and receive notifications of new posts by email.

Website Powered by WordPress.com.

  • Follow Following
    • Salesforce Everywhere
    • Already have a WordPress.com account? Log in now.
    • Salesforce Everywhere
    • Customize
    • Follow Following
    • Sign up
    • Log in
    • Report this content
    • View site in Reader
    • Manage subscriptions
    • Collapse this bar