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
sampathawaduge sameerasampathawaduge sameera 

Storing SOSL

Why do we need to store SOSL result in List<List<sObject>> ?
akashdeeparoraakashdeeparora
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
Hi,

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}))