Skip to main content
Hello All,

I am working on a LWC.  Currently I can retrieve the record Id and pass it to a handler

@api recordId;

console.log('Job RecordId is ' + this.recordId);

getContactName{recordId : this.recordId})

Now I want to pass another field off the record but unsure how to retrieve it.  I tried this but it does not work

import JOB_NAME_FIELD from '@salesforce/schema/Contact__c.Job_Name__c';

getFieldValue(this.recordId, JOB_NAME_FIELD);

Any suggestions would be greatly appreciated.

Thanks

P

 
3 respuestas
  1. 16 ene 2022, 21:12
    Phuc Nguyen, 

    Please try the below and see if it works- 

     

    /// We will first want to import get record from Lightning/UiRecordApi.

    import {

    getRecord

    } from 'lightning/uiRecordApi';

    // then we can name as many fields as we want from the object in the below fashion.

    import NAME_FIELD from '@salesforce/schema/User.Name';

    import EMAIL_FIELD from '@salesforce/schema/User.Email';

    // Once above is implemented, we can use the wire service adapter to fetch the fields.

    @wire(getRecord, {

    recordId: Id,

    // As you can see here, instead of the field itself, like you have implemented, we are using 'fields' attribute from getrecord method to feed all the field values we need.

    fields: [NAME_FIELD, EMAIL_FIELD]

    }) wireuser({

    error,

    data

    }) {

    if (error) {

    this.error = error;

    } else if (data) {

    this.userName = data.fields.Name.value;

    this.userEmail = data.fields.Email.value;

    this.userPidm = data.fields.PIDM__c.value

    }

    }

    Note: for this to work, make sure you import 'wire' decorator to your component along with api.

    Let me know if this worked for you. 

     
0/9000