How to Access Record in Apex Returned by SOSL
What Is Return Type Of SOSL Query?
SOSL query returns a list of list records as in a SOSL query, and records can be of more than one sObject.
How To Access Record In Apex Returned By SOSL
Here is the below example for accessing the record returned by SOSL in Apex:
// Create a variable to store the results of the query.
List<sObject> records = [FIND {searchTerm} RETURNING FROM Account(Name) IN ALL FIELDS];
// Loop through the records and access the fields that you need.
for (SObject record : records) {
System.debug(record.get('Name'));
}

Join our newsletter: Get daily update on Salesforce career insights & news!
Join Now!
Need more support?
Get a head start with our FREE study notes!
Learn more and get all the answers you need at zero cost. Improve your skills using our detailed notes prepared by industry experts to help you excel.