Salesforce provides two different query and search languages for retrieving data: SOQL (Salesforce Object Query Language) and SOSL (Salesforce Object Search Language). Each language is optimized for different use cases.
SOQL is used when you know which specific object and fields to query and need precise, structured filtering. It is commonly used in List Views, Reports, and Apex code where accuracy and full result sets are required.
SOSL is used for full-text searches across multiple Salesforce objects simultaneously. It is similar to a web search engine in that it prioritizes relevance and speed, and is commonly used in global search, sidebar search, advanced search, and Apex code.
Understanding when to use each language is essential for Salesforce developers building Apex classes, Visualforce pages, and Lightning components.
The table below summarizes the key differences between SOQL and SOSL across dimensions such as full name, usage context, indexing behavior, search focus, and search scope.
| SOQL | SOSL | |
| Full Name | Salesforce Object Query Language | Salesforce Object Search Language |
| Used In | List Views, Reports, Apex | Global Search, Sidebar Search, Advanced Search, Apex |
| Indexing | Synchronous (supports Custom Indexes and Standard Indexes) | Asynchronous — typically 2–3 minutes. If over 9,000 records are loaded at one time, the excess are moved to the bulk index queue (slower). |
| Search Focus | Accuracy. Returns the full set of results that match the criteria. | Relevance and Speed. Similar to a web search. Weighting is placed on recently viewed records. |
| Search Scope | Can search one object at a time. | Can search multiple objects at a time. |
When to use SOQL: Use SOQL when you need to retrieve all records that match specific field criteria from a single object, such as filtering Accounts by Industry or Opportunities by Stage.
When to use SOSL: Use SOSL when you need to search for a term across multiple objects at once, such as finding all records (Accounts, Contacts, Leads) that contain a specific company name or email address.
Apex Developer Guide: SOQL and SOSL Queries
000385852

We use three kinds of cookies on our websites: required, functional, and advertising. You can choose whether functional and advertising cookies apply. Click on the different cookie categories to find out more about each category and to change the default settings.
Privacy Statement
Required cookies are necessary for basic website functionality. Some examples include: session cookies needed to transmit the website, authentication cookies, and security cookies.
Functional cookies enhance functions, performance, and services on the website. Some examples include: cookies used to analyze site traffic, cookies used for market research, and cookies used to display advertising that is not directed to a particular individual.
Advertising cookies track activity across websites in order to understand a viewer’s interests, and direct them specific marketing. Some examples include: cookies used for remarketing, or interest-based advertising.