Salesforce SOSL NOTES

(Notes from Trailhead Search Solution Basic

SOSL is a programmatic way of performing a text-based search against the search index.

Use SOSL when you don’t know in which object or field the data resides and you want to:

  • Retrieve data for a specific term that you know exists within a field. Because SOSL can tokenize multiple terms within a field and build a search index from this, SOSL searches are faster and can return more relevant results.
  • Retrieve multiple objects and fields efficiently, and the objects might or might not be related to one another.
  • Retrieve data for a particular division in an organization using the divisions feature, and you want to find it in the most efficient way possible.

APIs: Search (REST) and search() (SOAP) — Executes a SOSL text string search against your org’s data.

To search within a single object using SOSL, simply specify that object in the request. It’s just that easy.

FIND {term} RETURNING ObjectTypeName

Example —

FIND {march 2016 email} RETURNING Campaign

Adding another object- just add a comma-separated list.

FIND {term} RETURNING ObjectTypeName1, ObjectTypeName2, ObjectTypeNameYouGetTheIdea


FIND {recycled materials} RETURNING Product2, ContentVersion, FeedItem

Custom objects can be specified in SOSL.

Two basic search strategies -

  • Limit which data you’re searching through
  • Limit which data you’re returning

Use IN SearchGroup


RETURNING can be used for —

  • ObjectTypeName — Specifies the object to return.
  • FieldList — Specifies the fields to return.
  • ORDER By — Specifies which fields to order the results by. You can also specify ascending or descending order.
  • LIMIT n — Sets the maximum number of records returned for the given object.
  • OFFSET n — Sets the starting row offset into the result set returned by your query.

WITH filters

FIND {Cloud Kicks} RETURNING Account (Name, Industry)
FIND {race} RETURNING KnowledgeArticleVersion
(Id, Title WHERE PublishStatus=’online’ and language=’en_US’)
WITH DATA CATEGORY Location__c AT America__c
FIND {first place} RETURNING User (Id, Name),
FeedItem (id, ParentId WHERE CreatedDate = THIS_YEAR Order byCreatedDate DESC)
WITH NETWORK = ‘00000000000001’
Find {shoe} RETURNING Product2 WITH PricebookId = ‘01sxx0000002MffAAE’

Suggested Results

  • Search Suggested Records — Returns a list of suggested records whose names match the user’s search string. The suggestions resource provides a shortcut for users to navigate directly to likely relevant records, before performing a full search.
  • Search Suggested Article Title Matches — Returns a list of Salesforce Knowledge articles whose titles match the user’s search query string. Provides a shortcut to navigate directly to likely relevant articles before the user performs a search.
  • SObject Suggested Articles for Case — Returns a list of suggested Salesforce Knowledge articles for a case.

Admin Tasks

  • Setup synonym groups
  • Promoted search terms for Knowledge articles