[Salesforce]Lightning Web Component @wire decorator

Lightning Web Component @wire decorator

Sample

//js

import { LightningElement, wire } from 'lwc';
import { getRecord } from 'lightning/uiRecordApi';
import ACCOUNT_NAME_FIELD from '@salesforce/schema/Account.Name'; 
const FIELDS = [ACCOUNT_NAME_FIELD];

export default class LwcWire extends LightningElement {

    @wire(getRecord, { recordId: '0016T00002zj9rlQAA', fields: FIELDS})
    accountRecord;

    get NameOfAccountRecord() {
        if(this.accountRecord.data) {
            return this.accountRecord.data.fields.Name.value;
        }
        return null;
    }

}
//html

<template>
    <lightning-card>
        name : {NameOfAccountRecord}
    </lightning-card>
</template>
<?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

コメントを残す

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