In my Lightning Web Component I am passed the accountId and recordtypeId amongst a few other fields. I need to determine which recordtype the account is in order to display different parts in the component's html. This part gets me the recordtypeIDS if I pass it the Name, but I want it the other way around. I have the Id, but need the name.
@wire(getObjectInfo, { objectApiName: ACCOUNT_OBJECT })
objectInfo;
get recordTypeId() {
// Returns a map of record type Ids
const rtis = this.objectInfo.data.recordTypeInfos;
return Object.keys(rtis).find(
rti => rtis[rti].name === 'myAccountRecordType'
);
}
I tried accessing the RecordTypeDeveloperName from the account passed in, but couldn't find a way to do that - if I could, that would save me having to look it up. Is that possible? It didn't like me adding the .RecordType.DeveloperName.value to the fields.
const FIELDS = [
"Account.Id",
"Account.FirstName",
"Account.LastName",
"Account.PersonEmail",
"Account.RecordType",
"Account.isPersonAccount"
];
//Account variables
@track fname;
@track lname;
@track aemail;
@track aid;
@track arectype;
@track arectypeid;
@track isPerson;
@wire(getRecord, { recordId: "$recordId", fields: FIELDS })
wiredAccount({ error, data }) {
if (data) {
this.record = data;
this.aid = this.record.fields.Id.value;
this.fname = this.record.fields.FirstName.value;
this.lname = this.record.fields.LastName.value;
this.aemail = this.record.fields.PersonEmail.value;
this.arectype = this.record.fields.RecordTypeId.value;
this.isPerson = this.record.fields.isPersonAccount.value;
this.error = undefined;
} else if (error) {
this.error = error;
this.record = undefined;
}
}
In my HTML I'm trying to determine whether the Account is a Person type or not. Using IsPersonAccount doesn't work, and I don't know how else to work out the type of account.
<div class="slds-form-element__control slds-m-around_medium">
<lightning-record-view-form record-id={recordId} object-api-name="Account">
<div class="slds-grid slds-box">
<div class="slds-col slds-size_1-of-2">
<lightning-output-field field-name="Name"></lightning-output-field>
<template if:true={isPersonAccount}>
<lightning-output-field field-name="PersonEmail"></lightning-output-field>
</template>
</div>
</div>
</lightning-record-view-form>
</div>