Newer Version Available
WHERE conditionExpression
conditionExpression
The conditionExpression of the WHERE clause uses the following syntax:
You can add multiple field expressions to a condition expression by using logical operators.
- FIND {test} RETURNING Account (id WHERE createddate = THIS_FISCAL_QUARTER)
- FIND {test} RETURNING Account (id WHERE cf__c includes('AAA'))
fieldExpression
A fieldExpression uses the following syntax:
where:
| Syntax | Description |
|---|---|
| fieldName | The name of a field for the specified object. Use of single or double quotes around the name result in an error. You must have at least read-level permissions to the field. It can be any field except a long text area field, encrypted data field, or base64-encoded field. The name doesn’t need to be a field in the fieldList. |
| comparisonOperator | Operators that compare values, such as =,<=, IN, and LIKE. Operators are case insensitive for most fields, but case sensitive for case-sensitive fields. |
| value | A value used to compare with the value in the fieldName. Supply a value whose data type matches the field type of the specified field. The value must be a valid value, not other field names or calculations. If quotes are required, use single quotes. Double quotes result in an error. Quotes are unnecessary for dates and numbers. |
Comparison Operators
The following table lists the comparisonOperator values that are used in fieldExpression syntax. Comparisons on strings are case-insensitive.
| Operator | Name | Description |
|---|---|---|
| = | Equals | Expression is true if the value in the fieldName equals the value in the expression. String comparisons using the equals operator are case-sensitive for unique case-sensitive fields and case-insensitive for all other fields. |
| != | Not equals | Expression is true if the value in the fieldName doesn’t equal the specified value. |
| < | Less than | Expression is true if the value in the fieldName is less than the specified value. |
| <= | Less or equal | Expression is true if the value in the fieldName is less than, or equals, the specified value. |
| > | Greater than | Expression is true if the value in the fieldName is greater than the specified value. |
| >= | Greater or equal | Expression is true if the value in the fieldName is greater than or equal to the specified value. |
| LIKE | Like | Expression is true if the value in the fieldName matches the
characters of the text string in the specified value. The LIKE operator in SOQL and SOSL provides a mechanism for
matching partial text strings and includes support for wildcards.
For example, the following query matches Appleton, Apple, and Appl, but not
Bappl:
|
| IN | IN | If the value equals any one of the values in a WHERE clause. For example:
The values for IN must be in parentheses. String values must be surrounded by single quotes. You can also use IN and NOT IN for semi-joins and anti-joins when querying on ID (primary key) or reference (foreign key) fields. |
| NOT IN | NOT IN | If the value doesn’t equal any of the values in a WHERE clause. For example:
The values for NOT IN must be in parentheses. String values must be surrounded by single quotes. |
| INCLUDES EXCLUDES | Applies only to multi-select picklists. |
Logical Operators
The following table lists the logical operator values that are used in fieldExpression syntax:
| Operator | Syntax | Description |
|---|---|---|
| AND | fieldExpressionX AND fieldExpressionY | true if both fieldExpressionX and fieldExpressionY are true. |
| OR | fieldExpressionX OR fieldExpressionY |
true if either fieldExpressionX
or fieldExpressionY is true. Relationship queries with foreign key values in an OR clause behave differently depending on the version of the API. In a WHERE clause that uses OR, if the foreign key value in a record is null, the record is returned in version 13.0 and later, but not returned in versions before 13.0. |
| NOT | not fieldExpressionX |
true if fieldExpressionX is
false. There is also a comparison operator NOT IN, which is different from this logical operator. |
Quoted String Escape Sequences
You can use the following escape sequences with SOSL:
| Sequence | Meaning |
|---|---|
| \n or \N | New line |
| \r or \R | Carriage return |
| \t or \T | Tab |
| \b or \B | Bell |
| \f or \F | Form feed |
| \" | One double-quote character |
| \' | One single-quote character |
| \\ | Backslash |
| LIKE expression only: \_ | Matches a single underscore character ( _ ) |
| LIKE expression only:\% | Matches a single percent sign character ( % ) |
If you use a backslash character in any other context, an error occurs.
Example WHERE Clauses
| Example(s) |
|---|
|
|
|
|
|
|
|
|
|
|
| To search for a Salesforce Knowledge
article by
ID: |
| To search for multiple Salesforce Knowledge
articles by
ID: |
| To search for "San Francisco" in all fields of all
My_Custom_Object__c objects
that have a geolocation or address location within 500 miles of the
latitude and longitude coordinates 37 and 122,
respectively: |