Newer Version Available
Salesforce Object Query Language (SOQL)
Use the Salesforce Object Query Language (SOQL) to search your organization’s
Salesforce data for specific information. SOQL is similar to the SELECT statement in the widely
used Structured Query Language (SQL) but is designed specifically for Salesforce
data.
With SOQL, you can construct simple but powerful query strings in the following environments:
Similar to the SELECT command in Structured Query Language (SQL), SOQL allows you to specify the source object (such as Account), a list of fields to retrieve, and conditions for selecting rows in the source object.
SOQL uses the SELECT statement combined with filtering statements to return sets of data, which can optionally be ordered:
1SELECT one or more fields
2FROM an object
3WHERE filter statements and, optionally, results are ordered For example, the following SOQL
query returns the value of the Id and Name field for
all Account records if the value of Name is Sandy:
1SELECT Id, Name
2FROM Account
3WHERE Name = 'Sandy'For a complete description of the syntax, see SOQL SELECT Syntax.
When to Use SOQL
Use SOQL when you
know which objects the data resides in, and you want to:
- Retrieve data from a single object or from multiple objects that are related to one another.
- Count the number of records that meet specified criteria.
- Sort results as part of the query.
- Retrieve data from number, date, or checkbox fields.