What Is SOSL In Salesforce?
SOSL is a highly optimized way of searching records in Salesforce across multiple Objects that are specified in the query. A SOSL query returns a list of list of sObjects and it can be performed on multiple objects.
When To Use SOSL In Salesforce
Whether you use SOQL or SOSL depends on whether you know which objects or fields you want to search, plus other considerations.
Use SOSL when you 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. 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 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.
The basic difference between SOQL and SOSL is that SOSL allows you to query on multiple objects simultaneously whereas in SOQL we can only query a single object at a time.
Key Points On SOSL In Salesforce
Some key point:
- In query editor, Find {Test}.
- Find {Test} RETURNING Account(name), Contact(Name).
- Text searches are case-insensitive.
- Find {Test*} where asterisk(*) is a wildcard.
- Find {Test} in Name Fields.
- Whenever referring to ALL FIELDS, use * for emails and when specifying EMAIL fields, no need for *.
- Find {What?} [What type?] [Where?].
- Find {Upsert} RETURNING Account(Name,Phone), Contact(LastName), student__c(Name, Name__c).
- Find {test OR upsert}.
- In order to limit characters
- Find {Test??} ? => single character.
* => zero or multiple character.
- SOSL does not have to use a wildcard (*) as it already matches the fields based on the string match.