getRelatedListInfo

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

構文 

1import { LightningElement, wire } from 'lwc';
2import { getRelatedListInfo } from 'lightning/uiRelatedListApi';
3import ACCOUNT_OBJECT from '@salesforce/schema/Account';
4
5export default class LdsGetRelatedListInfo extends LightningElement {
6  @wire(getRelatedListInfo, {
7      parentObjectApiName: ACCOUNT_OBJECT.objectApiName,
8      relatedListId: 'Contacts',
9      recordTypeId: '012000000000000AAA' //optional
10      fields: ['Contact.Name', 'Contact.Id'] //optional
11      optionalFields: ['Contact.OptionalField'] //optional
12      restrictColumnsToLayout: false //optional
13  })
14}

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

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

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

パラメータ 

  • parentObjectApiName — (必須) 関連リストを取得する必要がある親オブジェクトの API 参照名 (取引先など)。
  • relatedListId — (必須) Contacts、Opportunities、Cases などの関連リストオブジェクトの API 名。
  • recordTypeId — (省略可能) 親レコードタイプの ID。指定されていない場合は、デフォルトのレコードタイプが使用されます。
  • fields — (省略可能) 関連リストの項目の API 参照名。
  • optionalFields — (省略可能) 関連リスト内の追加項目の API 参照名。
  • restrictColumnsToLayout — (省略可能) ページレイアウトのリスト列のメタデータのみを取得するか (true)、すべての列のメタデータを取得するか (false) を示します。デフォルト値は、true です。列をさらに絞り込むには、restrictColumnsToLayoutfieldsoptionalFields で使用します。

戻り値 

使用方法 

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

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

関連トピック

The Japanese Summer '24 guide is now live

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