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:
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
0 comments:
Post a Comment