Loading

Differences Between SOQL and SOSL: Salesforce Query and Search Languages Explained

Дата публикации: May 16, 2026
Описание

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.

SOQLSOSL
Full NameSalesforce Object Query LanguageSalesforce Object Search Language
Used InList Views, Reports, ApexGlobal Search, Sidebar Search, Advanced Search, Apex
IndexingSynchronous (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 FocusAccuracy. 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 ScopeCan 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.

Дополнительные ресурсы
Номер статьи базы знаний

000385852

 
Загрузка
Salesforce Help | Article