This course is currently a work in progress. Please join the waitlist to receive regular updates.
Where clause in SOQL
The WHERE clause in SOQL (Salesforce Object Query Language) is used to find records that match specific conditions.
In an enterprise organization, use as many WHERE conditions as possible, especially on indexed fields, to enhance query performance.
SOQL queries can be executed from apex code, Visual studio code or in the Query Editor of the Developer Console.
Note
SOQL queries can only retrieve records from a single sObject if they meet the specified criteria.
Using WHERE clause in SOQL
Following is an example of using WHERE clause in SOQL to find the contacts where leadSource is 'Web'.
Loading...
In the above example:
- The SOQL query is enclosed in square brackets, starts with
[
and ends with a];
- The query statement starts with a
SELECT
keyword, followed by a set of comma-separated fields (e.g. id, name) that you want to query from an object. - The
FROM
keyword indicates the object (Contact) from which data is going to be queried from salesforce. - The
WHERE
helps filter data in a query by choosing specific fields and values.
Note
The SOQL query always returns a list of records unless you use a LIMIT statement to return only one record, or if it’s an aggregate query.
Try It Yourself
Loading...
Hide this example
Try It Yourself
Loading...