I am building LWC component to include it in Case Record page. My lwc component should display current Case Owner Name. As per Salesforce LWC wire Service Ref, here is the way to fetch reference/lookup records:-
import OWNER_NAME_FIELD from '@salesforce/schema/Account.Owner.Name';
This syntax works well in VS code for Account, Opportunity, Contact etc.
But following doesn't work:-
import OWNER_NAME_FIELD from '@salesforce/schema/Case.Owner.Name';
It also doesn't work with Lead. So assumption is, may be both record can be owned by Queue also so it throws error while saving in VS Code.
Although I can use Lightning Base component (Lightning-record-form
) OR using apex callout to get owner name for record but since SF already gives option to use wire service to fetch lookup record, I would like to use same for Case object. Does anyone has clue why Case and Lead aren't allowed to fetch owner name.
Best Answer
Correction in your question:
You are not really fetching records. You are getting the definitions of fields through imports.
Problem:
It seems there are bugs for importing fields definitions for some fields/objects like in your case Case/Lead Owner Name. Also you cannot import the field definition for Geolocation fields - for example
aLocation__longitude__s
andaLocation__latitude__s
Solution:
Until we get a fix from salesforce, You can directly use these fields like
'Case.Owner.Name'
in wire service as shown in below sample:Output: