0

I am not able to get account recordtype by using wired adaptor . Below is my code:

import { LightningElement,api, wire } from 'lwc';
import { getRecord,getFieldValue } from 'lightning/uiRecordApi';
import CONTACT_FIRST_NAME from '@salesforce/schema/Contact.FirstName';
import ACC_RECORD_TYPE_NAME from '@salesforce/schema/Contact.Account.RecordType.DeveloperName';
import ACCOUNT_NAME from '@salesforce/schema/Contact.Account.Name';


export default class Customer_360_Contact extends LightningElement {
    @api recordId;
    @apierrors;
    @wire(getRecord, { recordId: '$recordId', fields: [CONTACT_FIRST_NAME,ACCOUNT_NAME,ACC_RECORD_TYPE_NAME] })
    wiredData({error,data}){
        if(data){
            this.contactRecord=data;
            const recordtypename = getFieldValue(this.contactRecord.data,ACC_RECORD_TYPE_NAME);
            console.log('Accrecordtype-->'+recordtypename); //this is coming undenied
        }
        if(error){
            this.errors=error;
        }
    }
}

1 Answer 1

1

You are accessing data twice. Remove it from the getFieldValue call:

import { LightningElement, api, wire } from "lwc";
import { getRecord, getFieldValue } from "lightning/uiRecordApi";
import CONTACT_FIRST_NAME from "@salesforce/schema/Contact.FirstName";
import ACC_RECORD_TYPE_NAME from "@salesforce/schema/Contact.Account.RecordType.DeveloperName";
import ACCOUNT_NAME from "@salesforce/schema/Contact.Account.Name";

export default class GetRecordSpanningFields extends LightningElement {
  @api recordId;
  @api errors;

  @wire(getRecord, {
    recordId: "$recordId",
    fields: [CONTACT_FIRST_NAME, ACCOUNT_NAME, ACC_RECORD_TYPE_NAME]
  })
  wiredData({ error, data }) {
    if (data) {
      this.contactRecord = data;
      const recordtypename = getFieldValue(
        this.contactRecord,
        ACC_RECORD_TYPE_NAME
      );
      console.log("Accrecordtype-->" + recordtypename); //this is coming undenied
    }
    if (error) {
      this.errors = error;
    }
  }
}
3
  • Thanks!! !!!!!!
    – Raj SF
    Commented Jan 8, 2021 at 11:18
  • Hi, when I am setting other attribute inside if(data){} based upon the account record type then getting error like : LWC component's @wire target property or method threw an error during value provisioning. Original error: [customerLogo is not defined]. can you pls tell me why this is coming? customerLogo i am setting inside if(recordtypename==='test'){}
    – Raj SF
    Commented Jan 8, 2021 at 11:44
  • If I understand correctly, know that data is inmutable - you cannot set a new attribute in there
    – Alba Rivas
    Commented Jan 8, 2021 at 11:51

You must log in to answer this question.

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