Newer Version Available

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

Understanding Relationship Query Limitations

When you’re designing 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 35 child-to-parent relationships can be specified in a query. A custom object allows up to 25 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 cannot filter on the body of the note or attachment. You cannot filter against the content of textarea fields, blobs, or Scontrol components in any object. For example, the following query is valid, and returns all account names and the owner ID for any notes associated with the account:
    However, the following query is not valid, because it attempts to evaluate information stored in the body of the note:

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

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