I'm trying to display an LWC component on my contact that shows the Account Page, but I see no data when the page is loaded. (I'm using standard objects as a proxy here as the end goal is to use this for custom objects)
Any thoughts on why this is happening and suggestions to fix it??
Here's the HTML for the Component:
<lightning-card title="Account Information" icon-name="standard:account">
<template if:true={contact.data}>
<lightning-record-form
record-id={contact.data.fields.AccountId.value}
object-api-name="Account"
layout-type="Full"
mode="readonly"
>
</lightning-record-form>
</template>
<template if:true={error}>
<div class="slds-text-color_error">
<p>{error}</p>
</div>
</template>
</lightning-card>
</template>
Here's the Javascript for the Component (the Account ID is correctly shown when I open the Console logs):
import { getRecord } from "lightning/uiRecordApi";
import CONTACT_ACCOUNTID_FIELD from "@salesforce/schema/Contact.AccountId";
export default class AccountDisplay extends LightningElement {
@api recordId; // Contact record Id
error;
@wire(getRecord, { recordId: "$recordId", fields: [CONTACT_ACCOUNTID_FIELD] })
contact({ error, data }) {
if (data) {
console.log("Account Id:", data.fields.AccountId.value);
this.error = undefined;
} else if (error) {
console.error("Error:", JSON.stringify(error));
this.error = "Error fetching account information";
}
}
}
Here's the XML for the Component:
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>53.0</apiVersion>
<isExposed>true</isExposed>
<targets>
<target>lightning__RecordPage</target>
</targets>
<targetConfigs>
<targetConfig targets="lightning__RecordPage">
<objects>
<object>Contact</object>
</objects>
</targetConfig>
</targetConfigs>
</LightningComponentBundle>