Sunday, September 3, 2023

SOSL In Salesforce

 

Introduction to SOSL 

Salesforce Object Search Language (SOSL) is used to write queries to search text against the search index.

Always create filters that are selective, when building efficient SOSL queries. By default, SOSL queries scan all entities. The search engine can return maximum of 2,000 records after matching the searched term or text.

SOSL statements are basically used to find or search the text format data, email, and phone fields for multiple objects, including custom objects, that we have access to in a single query.


SOSL Syntax: 

FIND {Search Text} [IN Name/Email/Phone/All] RETURNING sObject(Fields to return);
Example: SOSL to search 'Pepsi' text in all fields and return Account Object’s name, industry as result.

FIND {Pepsi} IN ALL FIELDS RETURNING Account (Name, Industry);

Note: We can use multiple objects as returning data in SOSL.

Example: SOSL to search ‘Pepsi’ text in all fields and return Account Object’s name, industry and Contact Object’s name, email as result.

FIND {Pepsi} IN ALL FIELDS RETURNING Account (Name, Industry), Contact (Name, Email);

No comments:

Post a Comment

Mostly Viewed