Sunday, 19 June 2022

 getRelatedListInfo

Use this wire adapter to get the metadata for RelatedList.

  • parentObjectApiName—(Required) The API name of a parent object that you want to get related lists for, like an Account.
  • relatedListId—(Required) The API name of a related list object such as Contacts, Opportunities, or Cases.
  • recordTypeId—(Optional) The ID of the parent record type. If not provided, the default record type is used.

This code example fetches the metadata for the Opportunity-related list in the Account object, then iterates through the list of display columns.


HTML

<template>
    <lightning-card title="Get Opportunity Related List Information">
        <template if:true={displayColumns}>
            <div class="slds-m-around_medium">
                <template for:each={displayColumns} for:item="info">
                    <p key={info.fieldApiName}>
                        {info.label}
                    </p>
                </template>
            </div>
        </template>
    </lightning-card>
</template>

JS

import { LightningElement,wire } from 'lwc';
import { getRelatedListInfo } from 'lightning/uiRelatedListApi';
export default class GetRelatedListInfo extends LightningElement {
    error;
    displayColumns;
    @wire(getRelatedListInfo, {
        parentObjectApiName: 'Account',
        relatedListId: 'Opportunities',
    })listInfo({ error, data }) {
        if (data) {
            console.log('data',JSON.stringify(data))
            this.displayColumns = data.displayColumns;
            this.error = undefined;
        } else if (error) {
            this.error = error;
            this.displayColumns = undefined;
        }
    }
}

XML

<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
    <apiVersion>54.0</apiVersion>
    <isExposed>true</isExposed>
    <targets>
         <target>lightning__RecordPage</target>
    </targets>
</LightningComponentBundle>

RESULT








No comments:

Post a Comment