Newer Version Available

This content describes an older version of this product. View Latest

Lookup Relationships and Outer Joins

Beginning with API version 13.0, relationship SOQL queries return records, even if the relevant foreign key field has a null value, as with an outer join.

The change in behavior applies to the following types of relationship queries.

  • In an ORDER BY clause, if the foreign key value in a record is null, the record is returned in version 13.0 and later, but not returned in versions before 13.0. For example:

    Any case record for which AccountId is empty is returned in version 13.0 and later.

    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. In version 13.0 and later, records are returned even if Parent__r.id or Parent__r.name are null. In earlier versions, such records are not returned by the query.

  • In a WHERE clause that uses OR, if the foreign key value in a record is null, the record is returned in version 13.0 and later, but not returned in versions before 13.0. For example, if your organization has one contact with the value of its LastName field equal to foo and the value of its AccountId field equal to null, and another contact with a different last name and a parent account named bar, the following query returns only the contact with the last name equal to bar:
    The contact with no parent account has a last name that meets the criteria, so it is returned in version 13.0 and later.
  • In a WHERE clause that checks for a value in a parent field, if the parent does not exist, the record is returned in version 13.0 and later but is not returned in versions before 13.0. For example:

    Case record Id values are returned in version 13.0 and later, but are not returned in versions before 13.0.

  • 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.