getRelatedListCount

RelatedList のレコード件数を取得するには、このワイヤアダプタを使用します。

構文 

1import { LightningElement, wire } from 'lwc';
2import { getRelatedListCount } from 'lightning/uiRelatedListApi';
3
4export default class LdsGetRelatedListCount extends LightningElement {
5  @wire(getRelatedListCount, {
6      parentRecordId: '001RM000003UNu6YAG',
7      relatedListId: 'Contacts',
8  })
9}

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

1GET /ui-api/related-list-count/${parentRecordId}/${relatedListId}

「Get Related List Record Count (関連リストのレコード件数の取得)」を参照してください。

パラメータ 

  • parentRecordId — (必須) 関連リストを取得する必要がある親レコードの ID (取引先 ID など)。
  • relatedListId — (必須) Contacts、Opportunities、Cases などの関連リストオブジェクトの API 名。
  • maxCount — (省略可能) 返すレコードの最大数。デフォルト値は 20 です。

戻り値 

使用方法 

次のコード例は、関連リストのレコード件数を取得します。

1<!-- wireGetRelatedListCount.html -->
2<template>
3  <lightning-card title="wireGetRelatedListCount">
4    <template lwc:if={responseData}>
5      <div class="slds-m-around_medium">
6        <p key={responseData.count}>{responseData.count} : {responseData.hasMore}</p>
7      </div>
8    </template>
9  </lightning-card>
10</template>
1// wireGetRelatedListCount.js
2import { LightningElement, wire } from "lwc";
3import { getRelatedListCount } from "lightning/uiRelatedListApi";
4export default class WireGetRelatedListCount extends LightningElement {
5  error;
6  responseData;
7  @wire(getRelatedListCount, {
8    parentRecordId: "001RM000003UNu6YAG",
9    relatedListId: "Contacts",
10  })
11  listInfo({ error, data }) {
12    if (data) {
13      this.responseData = data;
14      this.error = undefined;
15    } else if (error) {
16      this.error = error;
17      this.responseData = undefined;
18    }
19  }
20}

関連トピック

The Japanese Summer '24 guide is now live

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