Newer Version Available
Salesforce Object Search Language (SOSL)
Use the Salesforce Object Search Language (SOSL) to construct text-based search
queries against the search index.
You can 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
When to Use SOSL
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.
Performance Considerations
If your searches are too general, they are slow and return too many results. Use the following clauses to define efficient text searches.
- 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 community ID to return.
- WITH PricebookId: Specifies the price book ID to return.
Navigating This Document
- To see a list of available resources, see SOSL Syntax.
- To get started working with SOSL, see Example Text Searches.