0
votes

Problem is with this line in JS code inside result function- return this.wirestoredrecords.data.LastName;

I am trying to get the Contact Fields Values using Getter and display in the HTML. PLS HELP.

**JS CODE:**

import { api, LightningElement, wire } from 'lwc';
import { getRecord } from 'lightning/uiRecordApi';
import Name from '@salesforce/schema/Contact.Name';
import LastName from '@salesforce/schema/Contact.LastName';
import Phone from '@salesforce/schema/Contact.Phone';

const contactfields = [Name, LastName, Phone];

export default class WireGetRecords extends LightningElement {
    @api recordId;
    datavalue;

    @wire(getRecord, { recordId: '$recordId', fields: contactfields })
    wirestoredrecords;

    get result(){

        return this.wirestoredrecords.data.LastName;

    }

}

**HTML CODE:**
<template>
    <lightning-card>
        <div>{recordId}</div>
        <div>{result}</div>
        <div></div>
    </lightning-card>
</template>```

What is the error you are gettting?Tushar
Hi @Tushar , I am getting below error- Error during LWC component connect phase: [Cannot read properties of undefined (reading 'LastName')]Praveen Behera