Identifying Parent and Child Relationships
Identify parent-child relationships by viewing Entity Relationship Diagrams (ERD) or by examining the enterprise WSDL for your organization.
You can identify parent-child relationships by viewing a diagram in the Salesforce Architect Diagram Gallery. However, not all parent-child relationships are exposed in SOQL, so to be sure you can query on a parent-child relationship by issuing the appropriate describe call. The results contain parent-child relationship information.
You can also examine the enterprise WSDL for your organization:
-
To find the names of child relationships, look for entries that contain the plural form of a child object and end with
type="tns:QueryResult". For example, from Account:In the example above, the child relationship name
Contactsis in the entry for its parent Account. -
For the parent of an object, look for a pair of entries, such as
AccountIdandAccount, where the ID field represents the parent object referenced by the ID, and the other represents the contents of the record. The parent entry has a non-primitive type,type="ens:Account".Not all relationships are exposed in the API. The most reliable method for identifying relationships is to execute a
describeSObjects()call. You can use the AJAX Toolkit to quickly execute test calls. -
For custom objects, look for a pair of entries with the relationship suffix
__r: