function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
gracy laylagracy layla 

SOSL Statements In Salesforce Apex

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.
 for example, you can return a list of accounts, contacts, opportunities and leds that begin with the phase map.
 
List < list < subject >> search list = [ find 'map*' In ALL FIELDS RETURNING Account (ID, Name), contact, opportunity, lead ];

  Note : 
  The syntax of the classon 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.
  Example:
FIND 'map*' IN ALL FIELDS RETURNING account (Id, Name], Contact, Opportunity, Lead.

In the Force.com API, the value of the FIND Clause is demarcated with braces.
For Example:
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]);
Waqar Hussain SFWaqar Hussain SF
What is this for? Do you have any question?