Salesforce introduced a new module lightning/uiRelatedListApi in the summer’22 release for the LWC framework, which includes new wire adapters for retrieving related list records.
- getRelatedListRecordsBatch—Returns record data for a batch of related lists.
- getRelatedListInfoBatch—Returns metadata for a batch of related lists.
I used the getRelatedListRecordsBatch wire adapter in the above LWC JS controller to retrieve the accounts-related lists (Contacts, Opportunities, Cases) data without writing apex code.
The result will return in JSON format:
Note: If a related list is not added to the parent object record’s page layout, you will not receive the result for that related list and will see an error message in the response. However, you will receive the response for other related lists.
The getRelatedListInfoBatch wire adapter will return related list metadata information.
Below wire adapters used for retrieving records, metadata, and record count from a related list are now widely available (GA).
- getRelatedListRecords—Returns record data for a related list.
- getRelatedListInfo—Returns metadata for a related list.
- getRelatedListsInfo—Returns metadata for related lists in an object’s default layout.
- getRelatedListCount—Returns the record count for a related list.
Use the getRelatedListRecords wire adapter to get single related list records.
<strong>parentRecordId</strong>— (Required) The ID of the parent record for which you want to retrieve related lists, such as an Account ID.
<strong>relatedListId</strong>— (Required) A related list object’s API name, such as Contacts, Opportunities, or Cases.
<strong>fields</strong>—(Optional) The API names of the column fields in the related list.
This wire adapter can be used to retrieve the metadata for multiple RelatedLists.
parentObjectApiName—(Required) The API name of a parent object, such as an Account, for which you want to retrieve related lists.
recordTypeID—(Optional) The parent record type’s ID
To obtain the RelatedList record count, use this wire adapter.
parentRecordId— (Required) The ID of the parent record for which you want to obtain related lists, such as an Account ID.
relatedListId— (Required) The API name of a related list object, such as Contacts, Opportunities, or Cases.