Use wire adapters to get related list records.

Use wire adapters to get related list record information without writing an apex code.

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.

Parameters

  • <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.

Returns

data returned in JSON format

getRelatedListsInfo

This wire adapter can be used to retrieve the metadata for multiple RelatedLists.

Parameters

  • 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

Returns

getRelatedListCount

To obtain the RelatedList record count, use this wire adapter.

Parameters

  • 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.

Returns

Arun Kumar
Arun Kumar

Arun Kumar is a Salesforce Certified Platform Developer I with over 7+ years of experience working on the Salesforce platform. He specializes in developing custom applications, integrations, and reports to help customers streamline their business processes. Arun is passionate about helping businesses leverage the power of Salesforce to achieve their goals.

Articles: 161

Leave a Reply

Discover more from SFDC Lessons

Subscribe now to keep reading and get access to the full archive.

Continue reading

Discover more from SFDC Lessons

Subscribe now to keep reading and get access to the full archive.

Continue reading