Logical Operators

Logical operators can be used in the field expression of the WHERE clause in a SOQL query. These operators are AND, OR, and NOT. Parentheses are required whenever you mix the operators.

The following table lists the logical operator values that are used in fieldExpression syntax:

OperatorSyntaxDescription
ANDfieldExpressionX AND fieldExpressionYtrue if both fieldExpressionX and fieldExpressionY are true.
ORfieldExpressionX OR fieldExpressionYtrue if either fieldExpressionX or fieldExpressionY is true.
NOTnot fieldExpressionXtrue if fieldExpressionX false. There’s also a comparison operator NOT IN, which is different from this logical operator.

In a WHERE clause that uses OR, records are returned even if the foreign key value in a record is null.

Example NOT operator: