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.

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:
    1<complexType name="Account">
    2                <complexContent>
    3                  <extension base="ens:sObject">
    4                    <sequence>
    5                      ...
    6                      <element name="Contacts" nillable="true" minOccurs="0"
    7                                     type="tns:QueryResult"/>
    8                      ...
    9                    </sequence>
    10                  </extension>
    11                </complexContent>
    12              </complexType>

    In the example above, the child relationship name Contacts is in the entry for its parent Account.

  • For the parent of an object, look for a pair of entries, such as AccountId and Account, 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".
    1<complexType name="Opportunity">
    2                <complexContent>
    3                  <extension base="ens:sObject">
    4                    <sequence>
    5                      ...
    6                      <element name="Account" nillable="true" minOccurs="0"   
    7                              type="ens:Account"/>
    8                      <element name="AccountId" nillable="true" minOccurs="0" 
    9                              type="tns:ID"/>
    10                      ...
    11                    </sequence>
    12                  </extension>
    13                 </complexContent>
    14               </complexType>

    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.

    Note

  • For custom objects, look for a pair of entries with the relationship suffix __r:
    1<complexType name="Mother__c">
    2           <complexContent>
    3            <extension base="ens:sObject">
    4             <sequence>
    5               ...
    6               <element name="Daughters__r" nillable="true" minOccurs="0" 
    7                     type="tns:QueryResult"/>
    8               <element name="FirstName__c" nillable="true" minOccurs="0" 
    9                     type="xsd:string"/>
    10               <element name="LastName__c" nillable="true" minOccurs="0" 
    11                     type="xsd:string"/>
    12               ...
    13              </sequence>
    14             </extension>
    15            </complexContent>
    16            </complexType>
    1<complexType name="Daughter__c">
    2           <complexContent>
    3            <extension base="ens:sObject">
    4             <sequence>
    5               ...
    6               <element name="Mother_of_Child__c" nillable="true" minOccurs="0" 
    7                     type="tns:ID"/>
    8               <element name="Mother_of_Child__r" nillable="true" minOccurs="0" 
    9                     type="xsd:string"/>
    10               <element name="LastName__c" nillable="true" minOccurs="0" 
    11                     type="ens:Mother__c"/>
    12               ...
    13              </sequence>
    14             </extension>
    15            </complexContent>
    16           </complexType>