Get Child Records

User Interface API has several resources that include child records in their responses. If a record has many child relationships, a response can be huge and have a negative effect on performance. To get only the records you need, request records for specific child relationships and set the page size of the results.

There are multiple resources that return child records. All of them share some common functionality.

Specify a Child Relationship

Specify child relationships in the format OBJECT_API_NAME.CHILD_RELATIONSHIP_NAME. For example, to specify the Contacts relationship on an account, use Account.Contacts.

Specify spanning relationships in the format OBJECT_API_NAME.CHILD_RELATIONSHIP_NAME.FIELD_API_NAME. For example, to specify the account billing address for an opportunity, use Opportunity.Account.BillingAddress.

Paginated Responses

The child relationships records in the response are paginated and include URLs to get the next page and previous pages of child records. Use the pageSize parameter to specify the number of records per page. The default is 5.

Responses Include One Level of Child Relationships

User Interface API gets the first set of child relationships that it finds, it doesn’t get the next level of child relationships. For example, this request gets the Opportunities on an Account record. If an opportunity in the response has a child relationship with another object, the API doesn’t return that information.

1GET /ui-api/record-ui/001R0000003IG0vIAG?childRelationships=Account.Opportunities

In this shortened response body, you see the first set of child relationships on the Account record, which in this case is three Opportunity records. The records in the next level of child relationships—on the Opportunity object—don’t appear because it would make the response body too large.

1...response shortened...
2"records" : {
3    "001RM000003TXRbYAO" : {
4      "apiName" : "Account",
5      "childRelationships" : {
6        "Opportunities" : {
7          "count" : 3,
8          "currentPageUrl" : "/services/data/v41.0/ui-api/records/001RM000003TXRbYAO/child-relationships/Opportunities?
9              fields=%5BOpportunity.Name%2C%20Opportunity.Id%5D&page=1&pageSize=5",
10          "nextPageUrl" : null,
11          "previousPageUrl" : null,
12          "records" : [ {
13            "apiName" : "Opportunity",
14            "childRelationships" : { },
15            "fields" : {
16              "AccountId" : {
17                "displayValue" : null,
18                "value" : "001RM000003TXRbYAO"
19              },
20              "Id" : {
21                "displayValue" : null,
22                "value" : "006RM000002XCGxYAO"
23              },
24              "Name" : {
25                "displayValue" : null,
26                "value" : "Acme - 1,200 Widgets"
27              }
28            },
29            "id" : "006RM000002XCGxYAO",
30            "recordTypeId" : "012000000000000000",
31            "recordTypeInfo" : null
32          },

Resources That Return Child Records 

Get Child Records for a Specific Record and Child Relationship

This example returns all the Contacts related to the Account record 001R0000003I6CoIAK.

1/ui-api/records/001R0000003I6CoIAK/child-relationships/Contacts

The response is paginated. Use the pageSize parameter to specify the number of records per page. The default is 5.

1{
2    "count" : 5,
3    "currentPageUrl" :
4    "/services/data/v41.0/ui-api/records/001R0000003I6CoIAK/child-relationships/Contacts?page=1&pageSize=5",
5    "nextPageUrl" :
6    "/services/data/v41.0/ui-api/records/001R0000003I6CoIAK/child-relationships/Contacts?page=2&pageSize=5",
7    "previousPageUrl" : null,
8    "records" : [ {
9        "apiName" : "Contact",
10        "childRelationships" : { },
11        "fields" : {
12            "AccountId" : {
13                "displayValue" : null,
14                "value" : "001R0000003I6CoIAK"
15            },
16            "Id" : {
17                "displayValue" : null,
18                "value" : "003R0000007qXwQIAU"
19            },
20            "Name" : {
21                "displayValue" : null,
22                "value" : "John Smith"
23            }
24        },
25        "id" : "003R0000007qXwQIAU",
26        "recordTypeId" : "012000000000000000",
27        "recordTypeInfo" : null
28    },
29    ...
30}
Get a Record and Include Child Records

This example gets the data for fields in the compact layout for an opportunity record with ID 006R0000001rboIIAQ. The response includes OpportunityCompetitors and Partners child records.

1GET /ui-api/records/006R0000001rboIIAQ?layoutTypes=Compact&childRelationships=Opportunity.OpportunityCompetitors,Opportunity.Partners
Get a Batch of Records and Include Child Records

This example gets the Account.Name field and Account.Contacts child records for two accounts.

1GET /ui-api/records/batch/001R0000003I6CeIAK,001R0000003I6CgIAK?
2  fields=Account.Name&childRelationships=Account.Contacts
Get Record Data and Metadata and Include Child Records

The response for this request includes layout information, metadata, and record data. The record data includes child relationship data for Contacts and Opportunities.

1GET /ui-api/record-ui/001R0000003I6CoIAK?childRelationships=Account.Contacts,Account.Opportunities

See Also