0

I have simple LWC component that isn't able to perform getRecord. I have to create custom component that will display Account data. When I try to retrieve account data it returns empty object. I saw similar topic here and this one, but it doesn't help me. What am I missing? JS code:

import { LightningElement, api, wire } from 'lwc';
import { getRecord } from 'lightning/uiRecordApi';
import EMAIL_FIELD from '@salesforce/schema/Account.PersonEmail';
import PHONE_FIELD from '@salesforce/schema/Account.Phone';
import BILLING_ADDRESS_FIELD from '@salesforce/schema/Account.BillingAddress';
import REWARD_INFO_FIELD from '@salesforce/schema/Account.RewardInfo__c';

const FIELDS = [EMAIL_FIELD, PHONE_FIELD, BILLING_ADDRESS_FIELD, REWARD_INFO_FIELD];
export default class Ps_GettingRecordDemo extends LightningElement {

  @api recordId;
  @wire(getRecord, { recordId: '$recordId', fields: FIELDS })
  account;

  renderedCallback(){
    console.log('rendered');
    console.log("acc:" + JSON.stringify(this.account));
    console.log("acc data:" + JSON.stringify(this.account.data));
    console.log("recordId:" + this.recordId);
  }
}

Markup:

<template>
  In my template
  Record Id is : {recordId}
  <br />
  <template if:true={account.data}>
      {account.data.fields.Phone.value}
  </template>
</template>

Meta xml:

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

Console output (renderedCallback is called only once):

rendered
acc:{}
acc data:undefined
record Id:0010v00000k9T5RAAU
2
  • 3
    "renderedCallback" is too early to check if(this.account) has data in it. It definitely will not have data in it until some time later.
    – sfdcfox
    Aug 26, 2021 at 11:44
  • It came out that the fields we are trying to retrieve with getRecord method can not be objects. Maybe it will help someone. Aug 26, 2021 at 13:20

0

You must log in to answer this question.

Browse other questions tagged .