Search code examples
salesforcesalesforce-lightning

Missing resource value for @salesforce/Schema/User.Name" Error


I am trying to display my name and email registered in salesforce using Lightning Web Component.

I imported User.Name and User.Email but still I am getting error. Could you tell me why this happens?

Thanks in advance.

Blockquote [Line: 4, Col: 23] LWC1512: Missing resource value for @salesforce/Schema/User.Name [Line: 5, Col: 23] LWC1512: Missing resource value for @salesforce/Schema/User.EMAIL

JS

import { LightningElement, wire, track, api } from 'lwc';
import { getRecord, getFieldValue } from 'lightning/uiRecordApi';
import USERID_FIELD from '@salesforce/user/Id';
import NAME_FIELD from '@salesforce/Schema/User.Name';
import MAIL_FIELD from '@salesforce/Schema/User.Email';

const FIELDS = [
    USERID_FIELD, NAME_FIELD, MAIL_FIELD
];

export default class JsSample extends LightningElement {
    @api recordId;

    @wire(getRecord, {'recordId': USERID_FIELD, fields: FIELDS})
    record;

    getName() {
        return getFieldValue(this.record.data, NAME_FIELD);
    }

    getEMail() {
        return getFieldValue(this.record.data, MAIL_FIELD);
    }

    @track inputText = '';

    handleChange(event){
        this.inputText = event.target.value;
    }

    /**
     * 初期化処理
     */
    connectedCallback(){

    }
}

HTML

<template>
    <div class="container">
        UserInfo<br>
        <div class="showProperties">
            Name:{name}<br>
            Mail:{eMail}
        </div>
    </div>

    <div class="おまけ">
        <label for="wireText">Input Text</label><input type="text" id="wireText" onchange={handleChange}/>
        <lightning-formatted-text value={inputText}></lightning-formatted-text>
    </div>
</template>

update: I cannot show my name using this code...

import { LightningElement, api, wire } from 'lwc';
import { getRecord, getFieldValue } from 'lightning/uiRecordApi';
import Id from '@salesforce/user/Id';
import NAME_FIELD from '@salesforce/schema/User.Name';
import MAIL_FIELD from '@salesforce/schema/User.EMail';

const FIELDS = "[NAME_FIELD, MAIL_FIELD]";

export default class JsSample extends LightningElement {
    @api recordId;
    userId = Id;
    @wire(getRecord, {recordId: '$userId', fields: FIELDS})
    user;
    get name() {
        return getFieldValue(this.user.data, NAME_FIELD);
    }
    get eMail() {
        return getFieldValue(this.user.data, MAIL_FIELD);
    }

    // @track inputText = '';

    // handleChange(event){
    //     this.inputText = event.target.value;
    // }

    // /**
    //  * init
    //  */
    // connectedCallback(){

    // }
}

Solution

  • Wire adaptors use lowercase camel case names, for instance salesforce and schema (apart from SObject and field names). Your references to the schema objects have incorrect case with the word Schema. They should be:

    import NAME_FIELD from '@salesforce/schema/User.Name';
    import MAIL_FIELD from '@salesforce/schema/User.Email';
    
    

    I made that correction and then pushed to my scratch org and it compiled and saved correctly.