getRelatedListInfo

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

構文 

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
  })
}

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

GET /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 関連リストのメタデータを取得し、表示列のリストを反復処理します。

<!-- wireGetRelatedListInfo.html -->
<template>
  <lightning-card title="wireGetRelatedListInfo">
    <template lwc:if={displayColumns}>
      <div class="slds-m-around_medium">
        <template for:each={displayColumns} for:item="col">
          <p key={col.fieldApiName}>{col.label}</p>
        </template>
      </div>
    </template>
  </lightning-card>
</template>
// wireGetRelatedListInfo.js
import { LightningElement, wire } from "lwc";
import { getRelatedListInfo } from "lightning/uiRelatedListApi";
import ACCOUNT_OBJECT from "@salesforce/schema/Account";

export default class WireGetRelatedListInfo extends LightningElement {
  error;
  displayColumns;
  @wire(getRelatedListInfo, {
    parentObjectApiName: ACCOUNT_OBJECT.objectApiName,
    relatedListId: "Contacts",
    recordTypeId: "012000000000000AAA", // optional
  })
  listInfo({ error, data }) {
    if (data) {
      this.displayColumns = data.displayColumns;
      this.error = undefined;
    } else if (error) {
      this.error = error;
      this.displayColumns = undefined;
    }
  }
}

関連トピック

The Japanese Summer '24 guide is now live

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