Sitemap
Ak

Ak

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

  1. 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}
  2. {“ “} 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)
  3. IN — it is used next of the value bracket to mention which field they need to search
  4. All,Name,Email,Phone — this are the keywords only need to use next of the IN keyword
  5. Fields — this is the keyword always we need to use next of that anyone of the keyword
  6. 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 TRACKING
String 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);
}

--

--