I need to understand where I am going wrong in the below piece of code. The error screenshot is shown below.
HTML Template:-
<template>
{name}
</template>
JS Controller:-
import { LightningElement,api,wire } from 'lwc';
import { getRecord } from 'lightning/uiRecordApi';
import LASTNAME_FIELD from '@salesforce/schema/Contact.LastName';
export default class FetchRecords extends LightningElement {
@api recordId;
@wire(getRecord, { recordId: '$recordId', fields:LASTNAME_FIELD})
contact;
get name(){
return this.contact.data.fields.LastName.value;
}
}
return this.contact.LastName;
assumingrecordId
is a Contact record Id I would expectcontact
to be a Contact SObject. Though you may also need a null guard as the data is loaded asynchronouslyreturn this.contact ? this.contact.LastName : '';
.