DEV Community

bhanukarkra
bhanukarkra

Posted on

SOSL in Salesforce

Salesforce Object Search Language (SOSL)to construct text-based search queries against the search index.

Syntax:
FIND {SearchQuery}
[ IN SearchGroup ]
[ RETURNING FieldSpec [[ toLabel(fields)] [convertCurrency(Amount)] [FORMAT()]] ]
[ WITH DivisionFilter ]
[ WITH DATA CATEGORY DataCategorySpec ]
[ WITH SNIPPET[(target_length=n)] ]
[ WITH NETWORK NetworkIdSpec ]
[ WITH PricebookId ]
[ WITH METADATA ]
[ LIMIT n ]

[ UPDATE [TRACKING], [VIEWSTAT] ]

By default, SOSL queries scan all entities. The search engine looks for matches to the search term across a maximum of 2,000 records.

Search text, email, and phone fields for multiple objects, including custom objects, that you have access to in a single query in the following environments.
*SOAP or REST calls
*Apex statements
*Visualforce controllers and getter methods
*Schema Explorer of the Eclipse Toolkit

If your org has relationship queries enabled, SOSL supports SOQL relationship queries.

When to USE:
Don’t know which object or field the data resides in, and you want to:
Retrieve data for a specific term that you know exists within a field.
Retrieve multiple objects and fields efficiently where the objects might or might not be related to one another.
Retrieve data for a particular division in an organization using the divisions feature.
Retrieve data that’s in Chinese, Japanese, Korean, or Thai. Morphological tokenization for CJKT terms helps ensure accurate results

To Refine search use clauses:
IN: Limits the types of fields to search, including email, name, or phone.
LIMIT: Specifies the maximum number of rows to return.
OFFSET: Displays the search results on multiple pages.
RETURNING: Limits the objects and fields to return.
WITH DATA CATEGORY: Specifies the data categories to return.
WITH DivisionFilter: Specifies the division field to return.
WITH NETWORK: Specifies the Experience Cloud site ID to return.
WITH PricebookId: Specifies the price book ID to return.

All detail available at
https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_sosl_syntax.htm

Top comments (0)