logo
shape

SOSL

Using the SOSL (Salesforce Object Search Language) syntax, we can formulate searches for specific values in one or many objects simultaneously. It allows you to search for data in different objects that are not in a direct parent-child relationship

SOSL – Salesforce Object Search Language
Mastering Fuzzy Search with SOSL
This trick is about using the wildcard character (*) in SOSL to perform a fuzzy search on the Account object.

FIND {FuzzySearch*} IN ALL FIELDS RETURNING Account(Id, Name)
            
Performing Multi-object Search with SOSL
This trick showcases how to use SOSL to search across multiple objects (Account, Contact, Lead) and return specific fields from each object.

FIND {Nasir} IN ALL FIELDS RETURNING Account (Id, Name), Contact (Id, Name), Lead (Id, Name)
            
Limiting the Number of Rows Returned with SOSL
This example demonstrates how to limit the number of rows returned in a SOSL search using the LIMIT clause. Here, it limits the search to the top 5 Account records.

FIND {Amena} IN NAME FIELDS RETURNING Account(Id, Name LIMIT 5)
              
Using SOSL to Search in Email Fields
This trick highlights how to use SOSL to search specifically in email fields within the Contact object. It's useful when you know the search term is an email address.

FIND {Jason} IN EMAIL FIELDS RETURNING Contact(Id, Email)
                
Most Asked Questions about SOSL
How does SOSL differ from SOQL?

While both SOSL and SOQL (Salesforce Object Query Language) allow you to search your organization’s Salesforce data for specific information, they are used in different scenarios. SOQL is similar to the SELECT statement in SQL, and is used to retrieve specific data from specific objects based on the specified conditions. On the other hand, SOSL is used when you don't know in which object or field the data resides and you want to retrieve it based on a text search.

Can SOSL queries search all standard and custom fields?

No, SOSL queries don't search across all standard and custom fields. They search only specific standard fields and custom fields that are enabled for search. This is different from SOQL, which can query any standard or custom field. The fields searched in SOSL are generally the name fields, email fields, phone fields, and other fields that are commonly used in searches.

Are there limits on the number of SOSL queries that can be executed?

Yes, Salesforce does impose some governor limits on the execution of SOSL queries. As of 2023, Salesforce allows you to execute up to 20 SOSL queries per transaction. The maximum number of records that SOSL will return is 2,000. Beyond these limits, you will need to use strategies such as pagination to handle larger data sets. Always refer to the latest Salesforce documentation for the most up-to-date information on governor limits.

© All rights Reserved. 2023