Thursday, 1 October 2015

How to use Like Operator in SOSL

Hi All,

I have already explained about the LIKE operator in my earlier post.

http://salesforceworld4u.blogspot.in/2013/08/like-operator-in-salesforce_13.html

Some asked how to use Like operator in SOSL, Below is the some code snippet where Like operator being used in SOSL.
Lets find account,contact,lead and opportunities records whose name is containing test keyword

List<List<SObject>> searchList = [FIND 'Test*' IN ALL FIELDS RETURNING Account (Id, Name WHERE Name LIKE '%test%' limit 10),Contact(Id, Name WHERE Name LIKE '%test%' limit 10),Opportunity(Id, Name WHERE Name LIKE '%test%' limit 10),Lead(Id, Name WHERE Name LIKE '%test%' limit 10)];

Account [] accounts = ((List<Account>)searchList[0]);
System.debug('Printing size-- '+accounts.size());
System.debug('Printing size-- '+accounts );

Contact [] contacts = ((List<Contact>)searchList[1]);
System.debug('Printing size-- '+contacts.size());
System.debug('Printing size-- '+contacts);

Opportunity [] opportunities = ((List<Opportunity>)searchList[2]);
System.debug('Printing size-- '+opportunities.size());
System.debug('Printing size-- '+opportunities);

Lead [] leads = ((List<Lead>)searchList[3]);
System.debug('Printing size-- '+leads.size());
System.debug('Printing size-- '+leads);


No comments: