Understand SOQL Queries

SOQL is a query language that’s similar to SQL but designed for Salesforce data. To query data using Salesforce APIs, create a SOQL statement that defines the information you want to search for.

SOQL Statement Structure 

The basic structure of a SOQL statement resembles this example.

1SELECT _one or more fields_
2FROM _an object_
3WHERE _filter statements_
4ORDER BY _optional sorting rules to apply to the query_
5LIMIT _the maximum number of results to return_

For example, this SOQL query returns the value of the Id, FirstName, LastName, and Country fields for all contacts where the value of the MailingCountry field is NG. Results are returned in ascending order by LastName, and then in ascending order by FirstName. The maximum number of results returned is 25.

1SELECT Id, FirstName, LastName, MailingCountry
2FROM Contact
3WHERE MailingCountry = 'NG'
4ORDER BY LastName ASC, FirstName ASC
5LIMIT 25

Related Content