Play Games

Search This Blog

Wednesday, April 13, 2016

SOSL Query Example (or) How to use string variable in SOSL query

Example : To write a SOSL query  to return both contacts and leads that have first or last name matching with 'Smith'.
Piece Of Code:
string searchString = 'Smith';
List<List< SObject>> recordList = [FIND :searchString IN ALL FIELDS RETURNING Contact(name,id where firstname=:searchString or lastName =:searchString ),Lead(firstname,lastName,name where firstname=:searchString or lastName =:searchString)];
system.debug('recordListrecordList'+recordList);

Output :

No comments:

Post a Comment