Find your content:

Search form

You are here

Use the Salesforce Object Query Language (SOQL) to construct simple but powerful query strings in the following environments: In the queryStrin

 
Share

Use the Salesforce Object Query Language (SOQL) to 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.

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

    SELECT ***fieldList*** [subquery][...]
    [TYPEOF typeOfField whenExpression[...] elseExpression END][...]
    FROM objectType[,...] 
        [USING SCOPE filterScope]
    [WHERE conditionExpression]
    [WITH [DATA CATEGORY] filteringExpression]
    [GROUP BY {fieldGroupByList|ROLLUP (fieldSubtotalGroupByList)|CUBE (fieldSubtotalGroupByList)} 
    [HAVING havingConditionExpression] ] 
    [ORDER BY fieldOrderByList {ASC|DESC} [NULLS {FIRST|LAST}] ]
    [LIMIT numberOfRowsToReturn]
    [OFFSET numberOfRowsToSkip]
    [FOR {VIEW  | REFERENCE}[,...] ]
        [ UPDATE {TRACKING|VIEWSTAT}[,...] ]

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'

Useful Documentation


Attribution to: Sergej Utko
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/312

My Block Status

My Block Content