I work with the Lead object in an LWC component and I am new to LWC. I Can't get to do what I want with the lightning-record-*-form components so I intend to sur the @wire data link. TO better discover the use of @wire, I use and execute the "Get Record Data" sample code given in the documentation: enter link description here
The example works fine. So I decide to replace the Contact object of the example with a Lead object, and it fails with the following message: "Cannot read properties of undefined (reading 'data')". Lines and Columns are undefined.
So I revert to the version with Contact, and all works fine again.
Hence my question: is there an issue with the Lead object with LWC?
Notice: if I use the original code and pass it a Lead record ID, it works ok. Error is raised when I use the word 'Lead' or 'lead' in the LWC javaScript code.
Thank you for your help.
THe LWC code below:
HTML:
<template>
<lightning-card title="My Contact Record" icon-name="standard:contact">
<template if:true={contact.data}>
<div class="slds-m-around_medium">
<p>{name}</p>
<p>{title}</p>
<p><lightning-formatted-phone value={phone}></lightning-formatted-phone></p>
<p><lightning-formatted-email value={email}></lightning-formatted-email></p>
</div>
</template>
<template if:true={contact.error}>
</template>
</lightning-card>
JavaScript:
import { LightningElement, api, wire } from 'lwc';
import { getRecord } from 'lightning/uiRecordApi';
const FIELDS = [ 'Lead.Name', 'Lead.Title', 'Lead.Phone', 'Lead.Email', ];
export default class WireGetRecordDynamicContact extends LightningElement {
@api recordId;
@wire(getRecord, { recordId: '$recordId', fields: FIELDS })
lead;
get name() {
return this.lead.data.fields.Name.value;
}
get title() {
return this.lead.data.fields.Title.value;
}
get phone() {
return this.lead.data.fields.Phone.value;
}
get email() {
return this.lead.data.fields.Email.value;
}
}