[Salesforce]Lightning Web Component wiredRecord

Lightning Web Component wiredRecord

The wiredRecord function receives a stream of data from this wire service. The record data is then returned in the data argument. Any errors are returned in the error argument.

Samle

js

import { LightningElement, api, wire } from 'lwc';
import { getRecord, getFieldValue } from 'lightning/uiRecordApi';
import NAME_FIELD from '@salesforce/schema/Account.Name';
export default class AccountSummary extends LightningElement {
    @api recordId;
    accountName;
    data;
    error;

    @wire(getRecord, { recordId: '$recordId', fields: [NAME_FIELD] })
    wireRecord({ data, error}) {
        if (data) {
            this.accountName = getFieldValue(data, NAME_FIELD);
            this.data = data;
        } else if (error) {
            this.error = error;
        }
    }
}

html

<template>
    <lightning-card>
        <div>
            <template if:true={data}>
                Account Name : {data.fields.Name.value}
            </template>
        </div>
    </lightning-card>
</template>

js-meta.xml

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

Result

投稿者: kinkun

保有資格 Salesforce Certified Platform App Builder T Salesforce Certified Platform Developer I Salesforce Certified Platform Developer II Salesforce Certified Administrator

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です