getRelatedListRecordsBatch

Use this wire adapter to get records for a batch of RelatedLists.

Syntax 

1import { LightningElement, wire } from 'lwc';
2import { getRelatedListRecordsBatch } from 'lightning/uiRelatedListApi';
3
4export default class LdsGetRelatedListRecordsBatch extends LightningElement {
5  @wire(getRelatedListRecordsBatch, {
6    parentRecordId: '001RM000003UNu6YAG',
7    relatedListParameters: [
8      {
9        relatedListId: 'Contacts',
10        fields: ['Contact.Name','Contact.Id'],
11        sortBy: ['Contact.Name']
12      },
13      {
14        relatedListId: 'Opportunities',
15        fields: ['Opportunity.Name', 'Opportunity.Amount'],
16        sortBy: ['Opportunity.Amount'],
17        where: "{ and: [{ Name: { like: \"ACME%\" }}] }"
18      }
19    ]
20  })
21}

User Interface API Resource 

1POST /ui-api/related-list-records/batch/${parentRecordId}

See Get a Batch of Related List Records with a Request Body.

Parameters 

Parameter NameTypeDescriptionRequired?
parentRecordIdStringThe ID of the parent record that you want to get related lists for, like an Account ID.Yes
relatedListParametersObjectAn array of related list parameter collections.Yes

relatedListParameters has several properties.

relatedListParameters PropertyTypeDescriptionRequired?
relatedListIdStringThe API name of a related list object, like Contacts, Opportunities, or Cases.Yes
fieldsString[]The API names of the related list’s column fields.
optionalFieldsString[]The API names of additional fields in the related list.
pageSizeNumberThe number of list records to return per page.
sortByString[]An array of field API names to sort the related list by. Accepts only one value per request.
whereStringThe filter to apply to related list records, in GraphQL syntax.

Returns 

Usage 

This code example fetches a batch of related list records by parent ID and multiple related list objects, then iterates through the list of records.

1<!-- wireGetRelatedListRecordsBatch.html -->
2<template>
3  <template for:each={results} for:item="result">
4    <lightning-card
5      key={result.result.listReference.relatedListId}
6      title={result.result.listReference.relatedListId}>
7      <template lwc:if={result.result.count}>
8        <div class="slds-m-around_medium">
9          <template for:each={result.result.records} for:item="rec">
10            <p key={rec.fields.Name.value}>{rec.fields.Name.value}</p>
11          </template>
12        </div>
13      </template>
14    </lightning-card>
15  </template>
16</template>
1// wireGetRelatedListRecordsBatch.js
2import { LightningElement, wire } from "lwc";
3import { getRelatedListRecordsBatch } from "lightning/uiRelatedListApi";
4export default class WireGetRelatedListRecordsBatch extends LightningElement {
5  error;
6  results;
7  @wire(getRelatedListRecordsBatch, {
8    parentRecordId: "001RM000003UNu6YAG",
9    relatedListParameters: [
10      {
11        relatedListId: "Contacts",
12        fields: ["Contact.Name", "Contact.Id"],
13        sortBy: ["Contact.Name"],
14      },
15      {
16        relatedListId: "Opportunities",
17        fields: ["Opportunity.Name", "Opportunity.Amount"],
18        sortBy: ["Opportunity.Amount"],
19      },
20    ],
21  })
22  listInfo({ error, data }) {
23    if (data) {
24      this.results = data.results;
25      this.error = undefined;
26    } else if (error) {
27      this.error = error;
28      this.results = undefined;
29    }
30  }
31}

See Also

Release Preview

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.