---
schema_version: "1"
id: 793368e9da23e6632548966fcf959f9186b9b3f16668a396dafb367d02e37d4b
title: Identifying Parent and Child Relationships
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/platform/salesforce-soql-sosl/guides/soql-sosl/sforce-api-calls-soql-relationships-parent-child.md
canonical_url: https://developer.salesforce.com/docs/platform/salesforce-soql-sosl/guide/sforce-api-calls-soql-relationships-parent-child.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 7247569fb788b1f0576c86d73ca97941e1d8019f51237d01f3535fe0fe394393
products:
  - SOQL and SOSL Reference
  - Platform Developer Content
---

# 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](https://architect.salesforce.com/diagrams). 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:

  ```xml
               <complexType name="Account">
                  <complexContent>
                    <extension base="ens:sObject">
                      <sequence>
                        ...
                        <element name="Contacts" nillable="true" minOccurs="0"
                                       type="tns:QueryResult"/>
                        ...
                      </sequence>
                    </extension>
                  </complexContent>
                </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"`.

  ```xml
                <complexType name="Opportunity">
                  <complexContent>
                    <extension base="ens:sObject">
                      <sequence>
                        ...
                        <element name="Account" nillable="true" minOccurs="0"
                                type="ens:Account"/>
                        <element name="AccountId" nillable="true" minOccurs="0"
                                type="tns:ID"/>
                        ...
                      </sequence>
                    </extension>
                   </complexContent>
                 </complexType>

  ```

  **note:** 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](https://developer.salesforce.com/docs/atlas.en-us.ajax.meta/ajax/) to quickly execute test calls.

- For custom objects, look for a pair of entries with the relationship suffix `__r`:

  ```xml
            <complexType name="Mother__c">
             <complexContent>
              <extension base="ens:sObject">
               <sequence>
                 ...
                 <element name="Daughters__r" nillable="true" minOccurs="0"
                       type="tns:QueryResult"/>
                 <element name="FirstName__c" nillable="true" minOccurs="0"
                       type="xsd:string"/>
                 <element name="LastName__c" nillable="true" minOccurs="0"
                       type="xsd:string"/>
                 ...
                </sequence>
               </extension>
              </complexContent>
              </complexType>
  ```

  ```xml
            <complexType name="Daughter__c">
             <complexContent>
              <extension base="ens:sObject">
               <sequence>
                 ...
                 <element name="Mother_of_Child__c" nillable="true" minOccurs="0"
                       type="tns:ID"/>
                 <element name="Mother_of_Child__r" nillable="true" minOccurs="0"
                       type="xsd:string"/>
                 <element name="LastName__c" nillable="true" minOccurs="0"
                       type="ens:Mother__c"/>
                 ...
                </sequence>
               </extension>
              </complexContent>
             </complexType>
  ```
