Newer Version Available

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

Understanding Relationship Query Limitations

When you design SOQL relationship queries, there are several limitations to consider.
  • Relationship queries are not the same as SQL joins. You must have a relationship between objects to create a join in SOQL.
  • No more than 55 child-to-parent relationships can be specified in a query. A custom object allows up to 40 relationships, so you can reference all the child-to-parent relationships for a custom object in one query.
  • No more than 20 parent-to-child relationships can be specified in a query.
  • In each specified relationship, no more than five levels can be specified in a child-to-parent relationship. For example, Contact.Account.Owner.FirstName (three levels).
  • In each specified relationship, only one level of parent-to-child relationship can be specified in a query. For example, if the FROM clause specifies Account, the SELECT clause can specify only the Contact or other objects at that level. It could not specify a child object of Contact.
  • You can query notes and attachments to get information about them, but you can’t filter on the body of the note or attachment. You can’t filter against the content of textarea fields, blobs, or Scontrol components in any object. For example, this query is valid, and it returns all account names and the owner ID for any notes associated with the account.
    1SELECT Account.Name, (SELECT Note.OwnerId FROM Account.Notes) FROM Account
    However, this query isn’t valid, because it attempts to evaluate information stored in the body of the note.
    1SELECT Account.Name, (SELECT Note.Body FROM Account.Notes WHERE Note.Body LIKE 'D%') FROM Account

    If you remove the WHERE clause, the query is valid and returns the contents of the body of the note.

    1SELECT Account.Name, (SELECT Note.Body FROM Account.Notes) FROM Account
  • You can’t use the USING SCOPE clause to limit the results of a parent-child relationship query to a specified scope.
  • Consider these limitations for external objects.
    • A subquery that involves external objects can fetch up to 1,000 rows of data.
    • Each SOQL query can have up to 4 joins across external objects and other types of objects.

      Each join requires a separate round trip to the external system when executing the query. Expect longer response times for each join in a query.

    • External objects don’t support the ORDER BY clause in relationship queries. This limit applies only when the external data is accessed via the OData 2.0 adapter for Salesforce Connect.
    • If the primary or “driving” object for a SELECT statement is an external object, queryMore() supports only that primary object and doesn’t support subqueries.