SOQL Where Clause
The SOQL WHERE
clause is used to filter records that match a certain condition. For example, you could use the following query to return every account with the billing country equal to France:
SELECT Id, Name, BillingCountry
FROM Account
WHERE BillingCountry = 'France'
We can also combine multiple logical tests in our WHERE
clause using AND
or OR
. If, for example, in our previous query, we only wanted to return the accounts with billing country equal to France that also had a billing city equal to ‘Paris’, we could use AND
to specify both conditions.
SELECT Id, Name, BillingCountry, BillingCity
FROM Account
WHERE BillingCountry = 'France'
AND BillingCity = 'Paris'
The following table show how to filter rows depending on field data type:
A string value is enclosed in single quotes |
|
A number value is written directly |
|
A boolean value is written as either true/false |
|
A date is written in this format (yyyy-mm-dd) |
|
A datetime is written in this format (yyyy-mm-ddThh:mm:ssZ) |
|
Note that a value can also be a date literal like (appointment_date__c = TODAY) which we will explain later.