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 ?

1 Answer 1

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
    Commented Jun 25, 2021 at 8:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .