1

I am trying to retrive field information for user fields using following code.
But except for the Name field of User, it is throwing error for every other field.
Any idea why its not letting me access user fields using schema.

I went ahead and tried Apex route also but same result.

import { LightningElement, wire, track } from 'lwc';
import USER_ID from '@salesforce/user/Id'; 
import NAME_FIELD from '@salesforce/schema/User.Name';
import PHONE_FIELD from '@salesforce/schema/User.Phone';
import ROLE_FIELD from '@salesforce/schema/User.UserRole.Name'; 

export default class myComponent extends LightningElement {
    @track error ; 
    @track name;
    @track phone;
    @track role;
    @wire(getRecord, {
         recordId: USER_ID,
         fields: [NAME_FIELD]
    }) wireuser({
         error,
         data
     }) {
         if (error) {
            this.error = error ; 
         } else if (data) {
             this.name = data.fields.Name.value;
             //this.phone = data.fields.Phone.value;             
             //this.role = data.fields.UserRole.value.fields.Name.value;
         }
     }
} 

Error Details:


Invalid reference User.Phone of type sobjectField in file myComponent.js: Source


Addtional Details:
I am using following extension for editing the code. Salesforce LWC Editor

7
  • You should have included the code as text as well.
    – sfdcfox
    May 9 at 23:21
  • @sfdcfox update the question. May 9 at 23:27
  • Are you using this component within experience cloud or regular lightning experience? May 10 at 1:07
  • @MohithShrivastava regular lightning experience, I am using LWC chrome extension. Salesforce LWC Editor. May 10 at 1:08
  • You mean chrome extension or chrome browser? May 10 at 1:09

1 Answer 1

0

This is a known issue with the LWC Deployment with the tooling API of Salesforce. If the underlying tool in your case the chrome extension uses tooling API for LWC Bundle deployment causing the issue.

Currently only workaround for this is to switch to alternate tools like SFDX CLI or use Salesforce VSCode extension to deploy your LWC component as those use Metadata API than using the tooling API.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.