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
Nagaraju Mogili 22Nagaraju Mogili 22 

Why we use the list<list<subject>> ?

Best Answer chosen by Nagaraju Mogili 22
Sohan Raj GuptaSohan Raj Gupta
Hi Nagaraju,

List<List<sObject>> means we have a list of a list of objects such as a list of account list, contact list, opportunity list, lead list

It is mainly use in SOSL, or also known as global search. 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]);
The example above has List<List<sObject>> of accounts, contacts, opportunities and Leads using the FIND search in SOSL.

Hope this will help you. Let me know if it helped or you need any more assistance. 

Please mark this is as the solution if it solved your purpose.

Thanks,
Sohan Raj Gupta