Boolean Operators
AVAILABLE API VERSION |
---|
API v56.0 and later |
To filter the result set, a query combines several predicates. Boolean operators can help you expand or narrow your query within the where
filter. Use the OR
function to combine filters. Use the AND
function to intersect filters. The NOT
function inverts a filter.
The filter types have fields for the AND
, OR
, and NOT
functions. AND
and OR
take in a list, while NOT
takes in a single filter to invert. When combined, the filters allow for arbitrary boolean expressions.
Each filter within the list of filters is joined by the named operator for AND
or OR
functions.
Let’s look at a list of filters with the and
operator.
Each filter is joined with the AND
SOQL operator.
Here's an example of the previous list of filters.
Similarly, consider the following filters.
The implicit filter with the and
operator is similar to a SOQL statement that looks like this.
Whenever two operators have a value on the filter type, the query combines them with an implicit AND operator.
This query is similar to the following SOQL statement. It assumes that Id
and Name
are included in a SELECT
clause.
Similarly, the following query contains multiple operators eq
and gt
with a value on the filter type.
The previous query is similar to the following SOQL statement. It assumes that Id
and Name
are included in a SELECT
clause.
Similarly, a filter with the or
operator looks like this.
The OR
function is similar to the following SOQL statement.
Let’s look at how to use the or
filter type.
The previous query is similar to this SOQL statement with the OR
operator. It assumes that Id
and Name
are included in a SELECT
clause.
The NOT
function inverts the predicate within the filter.
The previous query is similar to the following SOQL statement with the NOT
operator. It assumes that Id
and Name
are included in a SELECT
clause.
The NOT
function can be used with the binary functions as well.
The previous NOT
function is similar to the following SOQL statement.
This query uses the not
filter type with multiple and
filters.
The previous query is similar to the following SOQL statement with the WHERE NOT
clause.
Furthermore, we can have arbitrary nesting of filters.
The nesting of filter is similar as follows.
This query uses nesting of filters.
The previous query is similar to the following SOQL statement.