You need to sign in to do that
Don't have an account?
Henry Michel
How to get RecordTypeId in Lightning Web Component
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"
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"
Greetings to you!
I have written the following code as per your requirement. Please try the below code.
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Deepali Kulshrestha
www.kdeepali.com
All Answers
Greetings to you!
You can try like below:
I hope it helps you.
Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.
Thanks and Regards,
Khan Anas
Greetings to you!
I have written the following code as per your requirement. Please try the below code.
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Deepali Kulshrestha
www.kdeepali.com
import OPPORTUNITY_RECORDTYPE_FIELD from '@salesforce/schema/Opportunity.RecordType.ID';