0

I have a lookup field called Requested_By__c which looks up to User. It is on a custom object called Sample__c. In my LWC (sampleHelpInfo) I am using @wire to get the sample record and the ID of the user in the Requested_By__c field. Then I am using @wire again to get the email address of that user.

sampleHelpInfo.js:

import { LightningElement, api, wire, track } from 'lwc';
import { getRecord } from 'lightning/uiRecordApi';
import SAMPLE_REQUESTED_BY_FIELD from '@salesforce/schema/GT_Samples__c.Requested_By__c'
import USER_EMAIL_FIELD from '@salesforce/schema/User.Email'

export default class SampleHelpInfo extends LightningElement {
    @api recordId;
    sample;
    @track requestedById;
    @track requestedByEmail;
    @track user;

    @wire(getRecord, { recordId: '$recordId', fields: [SAMPLE_REQUESTED_BY_FIELD]})
        wiredSample({ error, data}) {
            if (data) {
                this.sample = data;
                this.error = undefined;
                this.requestedById = data.fields.Requested_By__c.value;
            } else if (error) {
                this.error = error;
                this.sample = undefined;
            }
        }

    @wire(getRecord, { recordId: '$requestedById', fields: [USER_EMAIL_FIELD]})
    wiredUser({ error, data}) {
        if (data) {
            this.user = data;
            this.requestedByEmail = data.fields.Email.value;
            this.error = undefined;
        } else if (error) {
            this.error = error;
            this.user = undefined;
        }
    }
}

sampleInfo.html:

<template>
    <div class="slds-align_absolute-center">
        <p>Please contact<a href="mailto:{requestedByEmail}"> {requestedByEmail}</a> for any requested sample amendments.</p>
    </div>
</template>

sampleHelpInfo.js-meta.xml:

<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
    <apiVersion>50.0</apiVersion>
    <isExposed>true</isExposed>
    <targets>
        <target>lightningCommunity__Default</target>
        <target>lightningCommunity__Page</target>
    </targets>
    <targetConfigs>
        <targetConfig targets="lightningCommunity__Default">
            <property name="recordId" type="String" label="Sample Record Id" description="Gives the component the record id of the sample in context" default="{!recordId}"></property>
        </targetConfig>
    </targetConfigs>
</LightningComponentBundle>

My problem is that when logged in as a user on a customer community licence I get the following error on wiredUser:

status": 404,
    "body": {
        "message": "The requested resource does not exist",
        "statusCode": 404,
        "errorCode": "NOT_FOUND"
    },
    "headers": {}

Is this because customer community licence users don't have access to the User object? I can't see anywhere on the profile that I can assign read access to the user object. The user email address is returned as expected when I am logged in on my admin profile.

2
  • 1
    does this help? help.salesforce.com/… or Sharing Rules?
    – cropredy
    Nov 18, 2020 at 2:01
  • wasn't able to solve my problem using this info but it's good to know. Thank you
    – Luke Bray
    Nov 18, 2020 at 10:59

1 Answer 1

0

I ended up just creating a formula field on my Sample object rather than using the LWC controller to look to the user.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .