Exception:
Unsupported reference Case.Owner.Email
Resolution:
Unsupported reference Case.Owner.Email Salesforce Exception is thrown when we try to import the email field of the Case Owner.
Case Owner field is a Polymorphic field. It can be a queue or an user. So, we cannot import it on the Salesforce Lightning Web Component.
Workaround:
Directly use the field ‘Case.Owner.Email’ when using getRecord wire method.
Sample Lightning Web Component:
HTML:
<template>
<lightning-card>
<div class="slds-p-around_small">
Case Owner Name is {name}<br/>
Case Owner Title is {title}<br/>
Case Owner Phone is {phone}<br/>
</div>
</lightning-card>
</template>
JavaScript:
import { LightningElement, api, wire } from 'lwc';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import { getRecord, getFieldValue } from 'lightning/uiRecordApi';
const FIELDS = [
'Case.Owner.Phone',
'Case.Owner.Title',
'Case.Owner.Name'
];
export default class CaseOwnerDetails extends LightningElement {
phone;
title;
name;
@api recordId;
@wire( getRecord, { recordId: '$recordId', fields: FIELDS } )
wiredRecord( { error, data } ) {
if ( error ) {
console.log(
'Error: ',
JSON.stringify( error )
);
let message = 'Unknown error';
if ( Array.isArray( error.body ) ) {
message = error.body.map(e => e.message).join(', ');
} else if ( typeof error.body.message === 'string' ) {
message = error.body.message;
}
this.dispatchEvent(
new ShowToastEvent({
title: 'Error loading contact',
message,
variant: 'error',
}),
);
} else if ( data ) {
console.log(
'Data: ',
JSON.stringify( data )
);
this.name = getFieldValue(
data,
'Case.Owner.Name'
);
this.title = getFieldValue(
data,
'Case.Owner.Title'
);
this.phone = getFieldValue(
data,
'Case.Owner.Phone'
);
}
}
}
js-meta.xml:
<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>62.0</apiVersion>
<isExposed>true</isExposed>
<targets>
<target>lightning__RecordPage</target>
</targets>
</LightningComponentBundle>