I am trying to access fields of account from the property "accountData" inside HTML file. by using the "." operator ie, accountData.Phone however I am getting error "Cannot read property 'Phone' of undefined"
//component1.html
<template>
<template if:true={accountData}>
<h2>Mobile number is {accountData.Phone}</h2>
</template>
</template>
//component1.javascript
import { LightningElement, wire,track,api } from 'lwc';
import getAccount from '@salesforce/apex/AccountController.getAccount';
export default class AccountRecord extends LightningElement {
originalData;
@api recordId;
@track accountData;
@wire(getAccount,{recordId:"$recordId"})
accountRecordData({error,data}){
if(data){
console.log("Data",data.Name);
this.accountData = data.AccountRecord;
//this.originalData = data;
}
else if(error){
console.log("ERROR",error);
//this.accountData = undefined;
}
}
I am a newbie in salesforce any help is highly appreciated