+ Start a Discussion
sampathawaduge sameerasampathawaduge sameera 

Storing SOSL

Why do we need to store SOSL result in List<List<sObject>> ?
SOSL has the ability to search across multiple objects in one query. So if you do something like the following it will return results from Accounts, Contacts, Opportunities, and Leads.

List<List<SObject>> searchList = [FIND 'map*' IN ALL FIELDS RETURNING Account (Id, Name), Contact, Opportunity, Lead];
Account [] accounts = ((List<Account>)searchList[0]);
Contact [] contacts = ((List<Contact>)searchList[1]);
Opportunity [] opportunities = ((List<Opportunity>)searchList[2]);
Lead [] leads = ((List<Lead>)searchList[3]);

Note - picklist fields are not searchable with SOSL.

Mark this as the "Best Answer" if it resolved your query.

Thanks & Regards,
Akashdeep Arora
Twitter - @akashdeeparora1
sampathawaduge sameerasampathawaduge sameera

Following is the idea I got.

Since the following result returns list of sObject list

((Account:{Name=Grand Hotels & Resorts Ltd, Id=0017F00000QKjHKQA1}), (Opportunity:{Name=Grand Hotels Guest Portable Generators, Id=0067F000008KxonQAC}, Opportunity:{Name=Grand Hotels SLA, Id=0067F000008Kxp6QAC}, Opportunity:{Name=Grand Hotels Generator Installations, Id=0067F000008KxoyQAC}, Opportunity:{Name=Grand Hotels Emergency Generators, Id=0067F000008Kxp8QAC}, Opportunity:{Name=Grand Hotels Kitchen Generator, Id=0067F000008KxokQAC}))