Note: This release is in preview. Features described here don’t become generally available until the latest general availability date that Salesforce announces for this release. Before then, and where features are noted as beta, pilot, or developer preview, we can’t guarantee general availability within any particular time frame or at all. Make your purchase decisions only on the basis of generally available products and features.

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 BY clause, the record is returned even if the foreign key value in a record is null. For example:

    Any case record for which AccountId is empty is returned.

    The following example uses custom objects:

    This query returns the Id and Name values of the Child object and the Id and name of the Parent object referenced in each Child, and orders the results by the parent name. Records are returned even if Parent__r.id or Parent__r.name are null.

  • In a WHERE clause that uses OR, 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 its LastName field equal to Young and the value of its AccountId field equal to null, and another contact with a different last name and a parent account named Quarry, the following query returns both contacts:
  • In a WHERE clause that checks for a value in a parent field, the record is returned even if the parent does not exist.. For example:

    Case record Id values are returned.

  • In a WHERE clause that uses a Boolean field, the Boolean field never has a null value. Instead, null is treated as false. Boolean fields on outer-joined objects are treated as false when no records match the query.