null Values in Lookup Relationships and Outer Joins
Relationship SOQL queries return records, even if the relevant foreign key field has a null value, as with an outer join.
-
In an
ORDER BYclause, the record is returned even if the foreign key value in a record is null. For example:Any case record for which
AccountIdis empty is returned.The following example uses custom objects:
This query returns the
IdandNamevalues of the Child object and theIdand name of the Parent object referenced in each Child, and orders the results by the parent name. Records are returned even ifParent__r.idorParent__r.nameare null. -
In a
WHEREclause that usesOR, records are returned even if the foreign key value in a record is null. For example, if your organization has one contact with the value of itsLastNamefield equal toYoungand the value of itsAccountIdfield equal tonull, and another contact with a different last name and a parent account namedQuarry, the following query returns both contacts: -
In a
WHEREclause that checks for a value in a parent field, the record is returned even if the parent does not exist.. For example:Case record
Idvalues are returned. -
In a
WHEREclause that uses a Boolean field, the Boolean field never has a null value. Instead,nullis treated asfalse. Boolean fields on outer-joined objects are treated as false when no records match the query.