contents
Documentation Version
Summer '15 (API version 34.0)
Language
English
  • Summer '15 (API version 34.0) 34.0
  • Spring '15 (API version 33.0) 33.0
  • Winter '15 (API version 32.0) 32.0
  • Summer '14 (API version 31.0) 31.0
  • Spring '14 (API version 30.0) 30.0
  • Winter '14 (API version 29.0) 29.0
  • English
  • Japanese

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:
  • In the queryString parameter in the query() call
  • In Apex statements
  • In Visualforce controllers and getter methods
  • In the Schema Explorer of the Force.com IDE

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.

Note

Note

SOQL doesn’t support all advanced features of the SQL SELECT command. For example, you can’t use SOQL to perform arbitrary join operations, use wildcards in field lists, or use calculation expressions.

SOQL uses the SELECT statement combined with filtering statements to return sets of data, which can optionally be ordered:

SELECT one or more fields 
FROM an object 
WHERE 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:
SELECT Id, Name
FROM Account
WHERE Name = 'Sandy'
Note

Note

Apex requires that you surround SOQL and SOSL statements with square brackets in order to use them on the fly. Additionally, Apex script variables and expressions can be used if preceded by a colon (:).

For a complete description of the syntax, see SOQL SELECT Syntax.
Note

Note

With archived data and BigObjects, you can use only some SOQL features. For more information, see SOQL with Archived Data.

Next