You are on page 1of 19

Salesforce.

com Object Query Language (SOQL)


Use the Salesforce.com 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 Eclipse Toolkit 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 SELECT Syntax


The SOQL SELECT statement uses the following syntax: SELECT fieldList FROM objectType [WHERE conditionExpression] [WITH [DATA CATEGORY] filteringExpression] [GROUP BY fieldGroupByList] | [GROUP BY ROLLUP|CUBE (fieldSubtotalGroupByList)] [HAVING havingConditionExpression] [ORDER BY fieldOrderByList ASC | DESC ? NULLS FIRST | LAST ?] [LIMIT ?]

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

SELECT one or more fields FROM an object WHERE filter statements and, optionally, results are ordered

SELECT Id, Name FROM Account WHERE Name = 'Smith'

Salesforce.com Object Search Language (SOSL)


SOSL allows you to specify the following for source objects:text expression scope of fields to search list of objects and fields to retrieve conditions for selecting rows in the source objects Pass the entire SOSL expression in the search parameter of the search() call.

Comparing SOSL and SOQL


Like Salesforce.com Object Query Language (SOQL), SOSL allows you to search your organizations Salesforce.com data for specific information. Unlike SOQL, which can only query one object at a time, a single SOSL query can search all objectsincluding custom objectsto which you have access. The API executes the search within the specified scope and returns to you only the information that is available to you based on the user permissions under which your application has logged in. Use SOQL with the query() call to select records for a single object. Use SOSL with the search() call to find records for one or more objects. The search() call searches most text fields on an object. See Search Scope for information on the fields searched.

SOSL Syntax
SOSL uses the following syntax: FIND {SearchQuery} [ toLabel()] [ IN SearchGroup [ convertCurrency(Amount)] ] [ RETURNING FieldSpec ] [ WITH DivisionFilter ] [ WITH DATA CATEGORY DataCategorySpec ] [ LIMIT n ]

Apex/sforce Explorer

You might also like