getRelatedListInfoBatch

RelatedLists のメタデータを一括で取得するには、このワイヤアダプタを使用します。

構文 

1import { LightningElement, wire } from 'lwc';
2import { getRelatedListInfoBatch } from 'lightning/uiRelatedListApi';
3import ACCOUNT_OBJECT from '@salesforce/schema/Account';
4
5export default class LdsGetRelatedListInfoBatch extends LightningElement {
6  @wire(getRelatedListInfoBatch, {
7    parentObjectApiName: ACCOUNT_OBJECT.objectApiName,
8    relatedListNames: ['Contacts', 'Opportunities'],
9  })
10}

ユーザインターフェース API リソース 

1GET /ui-api/related-list-info/batch/${parentObjectApiName}/${relatedListIds}

「Get a Batch of Related List Metadata (関連リストメタデータの一括取得)」を参照してください。

パラメータ 

  • parentObjectApiName — (必須) 関連リストを取得する必要がある親オブジェクトの API 参照名 (取引先など)。
  • relatedListNames — (必須) Contacts、Opportunities、Cases などの親オブジェクトのサポートされる関連リストの API 参照名が含まれるカンマ区切り文字列の配列。

ワイヤアダプタコードでは、relatedListNames はユーザインターフェース API リソースの relatedListIds に対応付けられます。

Note

  • recordTypeId — (省略可能) 親レコードタイプの ID。指定されていない場合は、デフォルトのレコードタイプが使用されます。

戻り値 

使用方法 

次のコード例では、Account オブジェクトの Contacts 関連リストおよび Opportunities 関連リストのメタデータを取得し、表示列のリストを反復処理します。

1<!-- wireGetRelatedListInfoBatch.html -->
2<template>
3  <template lwc:if={results}>
4    <div class="slds-m-around_medium">
5      <template for:each={results} for:item="result">
6        <lightning-card key={result.result.fieldApiName} title={result.result.label}>
7          <template for:each={result.result.displayColumns} for:item="col">
8            <p key={col.fieldApiName}>{col.label}</p>
9          </template>
10        </lightning-card>
11      </template>
12    </div>
13  </template>
14</template>
1// wireGetRelatedListInfoBatch.js
2import { LightningElement, wire } from "lwc";
3import { getRelatedListInfoBatch } from "lightning/uiRelatedListApi";
4import ACCOUNT_OBJECT from "@salesforce/schema/Account";
5
6export default class WireGetRelatedListInfoBatch extends LightningElement {
7  error;
8  results;
9  @wire(getRelatedListInfoBatch, {
10    parentObjectApiName: ACCOUNT_OBJECT.objectApiName,
11    relatedListNames: ["Contacts", "Opportunities"],
12  })
13  listInfo({ error, data }) {
14    if (data) {
15      this.results = data.results;
16      this.error = undefined;
17    } else if (error) {
18      this.error = error;
19      this.results = undefined;
20    }
21  }
22}

関連トピック

The Japanese Summer '24 guide is now live

日本語の Summer '24 ガイドが公開されました! 「Component Reference (コンポーネントリファレンス)」は、以前と同様にコンポーネントライブラリにあります。