Use null in WHERE
You can search for null values by using the null
keyword in SOQL queries.
This example query returns the account IDs of all events with a non-null activity date.
1SELECT AccountId
2FROM Event
3WHERE ActivityDate != nullIf you run a query on a boolean field, null matches FALSE values. For example, if Test_c is a boolean field, then the following query
returns all the account records where Test_c is
false:
1SELECT Id, Name Test_c
2FROM Account
3WHERE Test_c = nullThe clause WHERE Test_c = null is equivalent to WHERE Test_c = false. The clause WHERE Test_c != null is equivalent to WHERE Test_c = true.
The WHERE clause behaves in two different ways,
depending on the version, when handling null values in a parent field for a relationship
query. In a WHERE clause that
checks for a value in a parent field, the record is returned even if the parent
does not exist.
Case
record Id values are returned.
1SELECT Id
2FROM Case
3WHERE Contact.LastName = null