Loading...

The use of related lists within the Lightning UI has one of the greatest contributions in Salesforce development as it displays and manages connected records. As a result, it delivers users with a streamlined and unified view of associated data. Lightning UI Related List API allows developers to customize and enhance these lists, resulting in more functional, intuitive, and tailored lists.
In this blog, we will walk you through the functionalities of Related List API and its usage through a practical example.

Understanding the Lightning UI Related List API

The module of Lightning UI Related List API addresses several aspects of the related list management with the help of several wire adapters, such as:

getRelatedListInfo: Fetches metadata about a specifically related list.
getRelatedListsInfo: Retrieve the metadata of multiple related lists.
getRelatedListRecords: Collect records from related lists.
getRelatedListCount: Retrieves the count of records in a related list.
getRelatedListRecordsBatch: Fetches records from multiple related lists in batches.
getRelatedListInfoBatch: Retrieves metadata about multiple related lists in batches.

Utilizing getRelatedListCount

One of the key wire adapters within the lightning/uiRelatedListApi module is getRelatedListCount. With the help of this wire adapter, developers can retrieve the record count within a particular related list.

Let’s have a look at its parameters and results:

Parameters:

parentRecordId (Required): Retrieve related list information via parent record ID.
RelatedListId (Required): Includes API names of related list objects, like Contacts, Opportunities, or Cases.
maxCount (Optional): Use the default value of 20 and specify the maximum record numbers to return.

Result:

Count (Integer): The number of records in the related list.
hasMore (Boolean): Indicates whether there are more records beyond the retrieved set.
listReference: Provides a reference to the related list metadata.

Let’s explore a practical implementation of the getRelatedListCount wire adapter within a Lightning Web Component (LWC):

Understanding getRelatedListInfo

The getRelatedListInfo wire adapter is like a gateway that retrieves extensie metadata for related lists.
Let’s delve into its parameters and functionalities:

Parameters:

parentObjectApiName (Required): Fetch related lists through the API name of the parent object.
relatedListId (Required): Related list object’s API name.
recordTypeId (Optional): The ID of the parent record type, if applicable.
fields (Optional): Query the related list’s fields using their API names.
optional fields (Optional): A related list of additional fields is available for querying.
restrictColumnsToLayout (Optional): Determines whether metadata should be retrieved for only the list columns or all columns in the layout.

Implementing getRelatedListInfo

Let’s exhibit how to implement the getRelatedListInfo wire adapter within a Lightning Web Component (LWC):

Understanding getRelatedListInfoBatch

Developers can fetch metadata for a batch of related lists efficiently through getRelatedListInfoBatch.
Let’s examine its parameters and functionalities:

Parameters:

parentObjectApiName (Required): Refers to the API name of the parent object whose related lists you would like to retrieve.
relatedListNames (Required): Array containing API names for related lists supported by the API.

Implementing getRelatedListInfoBatch

Let’s demonstrate how to implement the getRelatedListInfoBatch wire adapter within a Lightning Web Component (LWC):

Understanding getRelatedListRecords

The getRelatedListRecords wire adapter gives an immaculate solution for retrieving records from related lists.
Let’s examine its parameters and functionalities:

Parameters:

parentRecordId (Required): Fetch related lists through the API name of the parent object.
relatedListId (Required): This is the API name of the related list object.
fields (Optional): The API names of the related list’s column fields to query.
optional fields (Optional): Additional fields in the related list to query.
pageSize (Optional): The number of list records to return per page.
sortBy (Optional): An array of field API names to sort the related list by.
where (Optional): The filter to apply to related list records, in GraphQL syntax.

Implementing getRelatedListRecords

Let’s demonstrate how to implement the getRelatedListRecords wire adapter within a Lightning Web Component (LWC):

Understanding getRelatedListRecordsBatch

The getRelatedListRecordsBatch wire adapter enables developers to fetch records for a batch of related lists with ease. Let’s delve into its parameters and functionalities:

Parameter:

parentRecordId (Required): Fetch related lists through the API name of the parent object.

relatedListParameters (Required): Each collection contains an array of related list parameters:

1. relatedListId (Required): This is the API name of the related list object.
2. fields (Optional): You can query the column fields of the related list by using the API names.
3. optional fields (Optional): There are additional fields in the related list for query.
4. pageSize (Optional): The number of list records to return per page.
5. sortBy (Optional): An array of field API names to sort the related list by.
6. where (Optional): The filter to apply to related list records, in GraphQL syntax.

Implementing getRelatedListRecordsBatch

Let’s demonstrate how to implement the getRelatedListRecordsBatch wire adapter within a Lightning Web Component (LWC):

Understanding getRelatedListsInfo

The getRelatedListsInfo wire adapter provides developers with the ability to retrieve metadata for related lists in an object’s default layout. Let’s examine its parameters and functionalities:

Parameter:

parentObjectApiName (Required): Fetch related lists through the API name of the parent object.
recordTypeId (Optional): The ID of the parent record type, if applicable.

Implementing getRelatedListsInfo

Let’s demonstrate how to implement the getRelatedListsInfo wire adapter within a Lightning Web Component (LWC):

The Bottom Line

Developers can easily fetch the metadata for related lists in Salesforce Lightning components by utilizing getRelatedListsInfo from the Lightning UI Related API module. From searching related lists for Accounts, Contacts, Opportunities, or other subjects, the Related API provides an effective approach to retrieving the metadata.
Consequently, it enables developers to manage different scenarios of accuracy and error, ensuring a flawless user experience.
So, unlock the full potential of Lightning components with advanced metadata querying capabilities!

Related Articles

Sticky notes aren’t just for your desk anymore! In this tutorial, we’ll create a Lightning Web Component (LWC) in Salesforce that allows you to pin notes on your app page or record page. With a clean, interactive UI, these digital sticky notes ensure you never forget important tasks or details. What Will You Learn? By […]

Read More
How to Create Dynamic, Animated Charts in Salesforce LWC using Chart.js

Bring Salesforce data to life with dynamic charts inside Lightning pages! While Salesforce dashboards are powerful, sometimes business users want visual insights without leaving their current page. That’s where Chart.js with Lightning Web Components (LWC) becomes a game-changer. In this step-by-step guide, you’ll learn how to: Upload Chart.js as a static resource in Salesforce. Build […]

Read More
How to Encrypt and Decrypt Data in Salesforce Using Apex Crypto Class

Data security is more important than ever. Whether you’re storing customer information, sensitive business data, or private communication, ensuring that your data stays safe is critical. Salesforce provides built-in tools to help with this, and one of the most powerful yet easy-to-use approaches is encryption and decryption using the Apex Crypto class. In this blog, […]

Read More
Benefits & Step-by-Step Setup Guide for Salesforce Code Analyzer

When building on the Salesforce platform, code quality and security are non-negotiable, especially before submitting your app for a Salesforce Security Review. Catching bugs and vulnerabilities early not only saves time but also ensures compliance with Salesforce’s best practices. That’s where the Salesforce Code Analyzer comes in. This open-source tool scans your Apex classes, triggers, […]

Read More
A Step-by-Step Guide to Integrate Zoho CRM with Salesforce (Without Coding)

Managing data across multiple CRMs can be a real challenge for businesses that want a single source of truth. If your teams use Zoho CRM but want to move or sync all records seamlessly into Salesforce, you don’t need to write a single line of code. Thanks to MultiSync Made Easy, the integration process is […]

Read More
How to Integrate Salesforce with Copilot

Integrating Salesforce with Copilot is becoming an essential step for organizations aiming to streamline workflows, automate client data management, and unlock the power of AI-driven CRM. By connecting these two platforms, businesses can centralize customer information, reduce manual tasks, and accelerate growth. This guide walks you through the Salesforce–Copilot integration process with clear steps, Apex […]

Read More