0

I have the following js code : -

export default class MapContact extends LightningElement {
    @wire(getRecord, { recordId: '0035g000007MUTlAAO', fields: [NAME_FIELD, ADD_FIELD] })
    contact
    getData() {
        console.log(this.contact);
        console.log(1221);
    }
}

and this is the html : -

<template>
    <button onclick={getData}>A button</button>
</template>

this.contact gives undefined. Is there anything wrong with this code ?

0

I'm assuming you have the necessary imports in place. If not,

import { getRecord,  getFieldValue } from 'lightning/uiRecordApi';

getFieldValue is optional. And try the updated code -

export default class MapContact extends LightningElement {
        @wire(getRecord, { recordId: '0035g000007MUTlAAO', fields: [NAME_FIELD, ADD_FIELD] })
        contact
        getData() {
            console.log(this.contact.data); //Change here
            console.log(1221);
        }
    }
1
  • 1
    @Aditya Also hope you are importing wire in js file
    – devforce
    Jun 25 '21 at 8:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.