Leverage the power of the getRelatedListInfo wire adapter in LWC!
The getRelatedListInfo wire adapter allows you to fetch metadata for a related list in a simplified manner.
This enables you to easily understand and work with related lists in Lightning Web Components.
Here's the syntax to use this wire adapter:
import { LightningElement, wire } from 'lwc';
import { getRelatedListInfo } from 'lightning/uiRelatedListApi';
import ACCOUNT_OBJECT from '@salesforce/schema/Account';
export default class LdsGetRelatedListInfo extends LightningElement {
@wire(getRelatedListInfo, {
parentObjectApiName: ACCOUNT_OBJECT.objectApiName,
relatedListId: 'Contacts',
recordTypeId: '012000000000000AAA', //optional
fields: ['Contact.Name', 'Contact.Id'], //optional
optionalFields: ['Contact.OptionalField'], //optional
restrictColumnsToLayout: false //optional
})
relatedListInfo;
}
Parameters
parentObjectApiName:
The API name of the parent object you want to retrieve related lists for, such as an Account.
relatedListId:
The API name of the related list object (e.g., Contacts, Opportunities, Cases).
recordTypeId: (Optional)
The ID of the parent record type. If not provided, the default record type is used.
fields: (Optional)
The API names of the related list's fields.
optionalFields: (Optional)
The API names of additional fields in the related list.
restrictColumnsToLayout: (Optional)
Indicates whether to retrieve metadata for only the list columns in the page layout or all columns.
The default value is true.
To further filter columns, use restrictColumnsToLayout with fields and optionalFields.
Follow Us