Authored by Zishan Razzaq

Thursday, November 29, 2012

How to use 'NOT LIKE' in SALESFORCE SOQL

Hi everyone:
    Business Scenario:
        They would like something update where a field on the record is NOT LIKE "adviser." Or in simplest terms does not contain "Adviser".

Solution for developers in APEX:

APEX will not allow someone to write a simple query such as:
SELECT Name From ABC where id=:Ownerid and Name NOT Like '%adviser%';

So solution is simple:
SELECT NAME From ABC where id=:Ownerid and (NOT Name Like  '%adviser%');

If you are utilizing GROUP By statements here is an example of one:


 AggregateResult[] groupedResults = 
         [SELECT Ownerid,Count(Id) ce 
         FROM Opportunity Where 
         Withdrawn__c = True 
         AND StageName = 'Closed Won' 
         AND Withdrawal_Status__c ='Withdrawn' 
         AND Withdrawn_Date__c = THIS_MONTH  
         AND Ownerid=:id 
         AND (NOT Name Like '%COMP%')
         GROUP BY Ownerid];  

Hope this Helps.
Thanks
Zishan



3 comments:

  1. hi, salesforce help ensures that your staff is perfectly trained in handling all the latest crm and related tools to make work a streamlined progressing activity.

    ReplyDelete
  2. Nice blog, Keep sharing such informative blog. I would like help student for expert training and guaranteed placement assistance for salesforce certification course

    ReplyDelete
  3. Dicsinnovatives in Delhi is one of the most reputed institution offering specialized digital marketing course in pitampura, Delhi. with 100% Placement ;Digital marketing institute in pitampura, Join now dicsinnovatives EMI Available. Enroll Now. Training.100+ Hiring Partners. Expert-Led Online Course. Industry Expert Faculty

    ReplyDelete