Salesforce Object Query language SOQL syntax is similar to SQL language. In SOQL, SELECT statement is used to specify the source object to retrieve data.

SOQL Syntax

</>
Copy
SELECT fields 
FROM Object 
WHERE Condition 
Ordering LIMIT
FOR VIEW Or FOR REFERENCE
OFFSET 
UPDATE VIEWSTAT

From the above SOQL syntax we have many things to observe and understand.  SELECT, fields, FROM and Object are required and all others are optional. Let us understand in detail.

NameDescription
FieldsThis denotes the API name of the fields of an object
ObjectThis denotes the custom object or standard object.
ConditionThis is use to filter records and it is optional.
OrderingThis is used for ordering the results and it is optional in the query.
Limit It is used to limit the number of fetched records.
FOR VIEWThis displays last viewed date for fetched records.
FOR REFERENCEThis displays last reference date for fetched records.
OFFSETIt is used to to fetch the starting row.
UPDATE VIEW STATE This updates the article’s view statistics for fetched records.

The API names of the fields are used in the SELECT statement. In our upcoming Salesforce developer tutorials we will learn about various SOQL syntax like Condition expression syntax using WHERE clause and field expression syntax.

Conclusion

In this Salesforce Developer Tutorial, we learned about Apex SOQL syntax.