in Salesforce by
SOSL Statements In Salesforce Apex?

► Click here to show 1 Answer

0 votes
SOSL statement evaluate to a list of sObjects, where each list contains the search results for a particular sobject type, The result lists are always returned in the same order as they were specified in the query.

If a SOSL query does not return any records for a specified sObject type, the search results include an empty list for that sObject.

Example: You can return a list of accounts, contacts, opportunities and leads that begin with the phase map.


List < list < subject >> search list = [ find 'map*' In ALL FIELDS RETURNING Account (ID, Name), contact, opportunity, lead ];


The syntax of the class on Apex differs from the syntax of the FIND clause in the SOAP API.

In Apex, the value of the FIND cause is demarcated with single quotes.


FIND 'map*' IN ALL FIELDS RETURNING account (Id, Name], Contact, Opportunity, Lead. In the API, the value of the FIND Clause is demarcated with braces.

FIND {map*} IN ALL FIELDS RETURNING account  [Id,name], contact ,opportunity,lead;

From search list , you can create arrays for each object returned.

Account [ ]  accounts = (( list < accounts > ) search list [0] );

Contact [ ]  contacts = [( list ) search list [0]) ;

Opportunity [ ] opportunities = ((list < opportunity> ) search list [2]) ;

Lead [ ] leads = (( list < lead> ) search list [3]);
Learn More with Madanswer

Related questions