Develop Secure Code
ui*Api Supported Objects
getRelatedListCount
getRelatedListInfo
getRelatedListInfoBatch
getRelatedListRecords
getRelatedListRecordsBatch
getRelatedListsInfo
getRelatedListRecordsUse this wire adapter to get RelatedList records. Related lists display details and links to records that are associated with a specific record. For example, an account can have related lists for contacts, cases, notes, or even files.
1import { LightningElement, wire } from 'lwc';
2import { getRelatedListRecords } from 'lightning/uiRelatedListApi';
3
4export default class LdsGetRelatedListRecords extends LightningElement {
5 @wire(getRelatedListRecords, {
6 parentRecordId: '001RM000003UNu6YAG',
7 relatedListId: 'Contacts',
8 fields: ['Contact.Name','Contact.Id'],
9 sortBy: ['Contact.Name']
10 })
11}1POST /ui-api/related-list-records/${parentRecordId}/${relatedListId}See Get Related List Records with a Request Body.
The /ui-api/related-list-info/${parentObjectApiName} resource returns related lists for an object, including the relatedListId values.
Tip
| Parameter Name | Type | Description | Required? |
|---|---|---|---|
parentRecordId | String | The ID of the parent record that you want to get related lists for, like an Account ID. | ![]() |
relatedListId | String | The API name of a related list or child relationship, like Contacts, Opportunities, or Cases. To provide an API name of a related list custom object, use the Custom_Objects__r format, where Custom_Objects is the plural form of your custom object name, and __r is the related list suffix. For more information on retrieving all related lists for an object or custom object, see RelatedListDefinition. | ![]() |
fields | String[] | The API names of the related list’s column fields. To use a standard field on a custom object, use the Custom_Object__c.FieldName format. To use a custom field on a custom object, use the Custom_Object__c.FieldName__c format. | |
optionalFields | String[] | The API names of additional fields in the related list. | |
pageSize | Number | The number of list records to return per page. The default value is 50. Enter a value between 1 and 1999. | |
sortBy | String[] | An array of field API names to sort the related list by. Accepts only one value per request. | |
where | String | The filter to apply to related list records. Semi-joins and anti-joins filters are currently not supported. For example, passing in a query using inq results in a Malformed Join Input Object error. |
data—Related List Record Collectionerror—FetchResponseThis code example fetches the related list records by parent ID and related list object, then iterates through the list of records.
1<!-- wireGetRelatedListRecords.html -->
2<template>
3 <lightning-card title="wireGetRelatedListRecords">
4 <template lwc:if={records}>
5 <div class="slds-m-around_medium">
6 <template for:each={records} for:item="rec">
7 <p key={rec.fields.Id.value}>{rec.fields.Name.value}</p>
8 </template>
9 </div>
10 </template>
11 </lightning-card>
12</template>1// wireGetRelatedListRecords.js
2import { LightningElement, wire } from 'lwc';
3import { getRelatedListRecords } from 'lightning/uiRelatedListApi';
4export default class WireGetRelatedListRecords extends LightningElement {
5 error;
6 records;
7 @wire(getRelatedListRecords, {
8 parentRecordId: '001RM000003UNu6YAG',
9 relatedListId: 'Contacts',
10 fields: ['Contact.Id', 'Contact.Name'],
11 where: '{ Name: { like: "Bob%" }}',
12 })
13 listInfo({ error, data }) {
14 if (data) {
15 this.records = data.records;
16 this.error = undefined;
17 } else if (error) {
18 this.error = error;
19 this.records = undefined;
20 }
21 }
22}See Also