SOSL
2 min readAug 26, 2026
salesforce object search language is used for search the field value across multiple object in a single time
Get Ak’s stories in your inbox
Join Medium for free to get updates from this writer.
easy to search and easy syntax
- FIND — it is used to find the value , Always we need to use this Find Keyword in the beginning of the search EX-FIND {John Smith}
- {“ “} this curly bracket is used to mention what word we need to search we can mention inside this we can search multiple words and we can use And,OR operator also inside this curly bracket EX-FIND {(John AND Smith) OR Kumar} IN NAME FIELDS RETURNING Contact(FirstName, LastName)
- IN — it is used next of the value bracket to mention which field they need to search
- All,Name,Email,Phone — this are the keywords only need to use next of the IN keyword
- Fields — this is the keyword always we need to use next of that anyone of the keyword
- RETURNING — this keyword we need to use next to fields keyword
After the returning keyword Always we need to mention the object what the objects it need to search
FIND {Smith}
IN ALL FIELDS
RETURNING
Contact(FirstName, LastName, Email WHERE MailingCity='Chennai' ORDER BY LastName ASC LIMIT 10),
Lead(FirstName, LastName, Company WHERE Status='Open' LIMIT 5),
Account(Name, Industry LIMIT 5)
WITH DIVISION = 'Global'
UPDATE TRACKINGString soslFindClause = 'Wingo OR SFDC';
List<List<sObject>> searchList = [FIND :soslFindClause IN ALL FIELDS
RETURNING Account(Name),Contact(FirstName,LastName,Department)];
List<Account> searchAccounts = (List<Account>)searchList[0];
ListContact> searchContacts = (List<Contact>)searchList[1];
System.debug('Found the following accounts.');
for (Account a : searchAccounts) {
System.debug(a.Name);
}
System.debug('Found the following contacts.');
for (Contact c : searchContacts) {
System.debug(c.LastName + ', ' + c.FirstName);
}



