• Antoine Fauque 10
  • NEWBIE
  • 10 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies
Hi guys, i'm trying to get RecordTypeId in a Lightning Web Component which is located on the Account record page. 
I'll explain this component accesses a picklist field that is different depending on the record type. So I wanted to add record-type-id to the lightning-record-edit-form that is present on my component but in don't know how to get this id in my JS.
I tried this : 
 
import { LightningElement, api, wire } from "lwc";
import { getRecord } from "lightning/uiRecordApi";
import ACCOUNT_RECORDTYPE_FIELD from '@salesforce/schema/Account.RecordTypeId';

export default class Account_Redirect extends NavigationMixin(LightningElement) {
  @api recordId;
  @api objectApiName;

  @wire(getRecord, { recordId: '$recordId', fields: [ACCOUNT_RECORDTYPE_FIELD] })
  acc;

  get recordTypeId() {
    return this.acc.data.fields.RecordTypeId.value;
  }
}
But i have the following error : 
"Cannot read property 'fields' of undefined" 

I'm not sure what to do to make it work.
If someone can help me on this or give me other way to get this recordTypeId
 
Hi guys, i'm trying to get RecordTypeId in a Lightning Web Component which is located on the Account record page. 
I'll explain this component accesses a picklist field that is different depending on the record type. So I wanted to add record-type-id to the lightning-record-edit-form that is present on my component but in don't know how to get this id in my JS.
I tried this : 
 
import { LightningElement, api, wire } from "lwc";
import { getRecord } from "lightning/uiRecordApi";
import ACCOUNT_RECORDTYPE_FIELD from '@salesforce/schema/Account.RecordTypeId';

export default class Account_Redirect extends NavigationMixin(LightningElement) {
  @api recordId;
  @api objectApiName;

  @wire(getRecord, { recordId: '$recordId', fields: [ACCOUNT_RECORDTYPE_FIELD] })
  acc;

  get recordTypeId() {
    return this.acc.data.fields.RecordTypeId.value;
  }
}
But i have the following error : 
"Cannot read property 'fields' of undefined" 

I'm not sure what to do to make it work.
If someone can help me on this or give me other way to get this recordTypeId