1

So my Lightning Web Component is working perfectly for me (sysadmin), time to test it for other users. Turns out that some things are working and others are not. What is working: calling Apex methods and processing the returned results. No problem there.

What is not working: getting data via Javascript @wire functions. They are being called, but they never collect any data from the server. The objects (Account, Opportunity) are owned by the user that is logged in, so they should be accessible.

This is a part of my code:

getAccRecordResult;
@track accRecord;
@wire(getRecord, { recordId: '$accId', fields: ACCOUNT_FIELDS } )
getAccRecord(result) {
  console.log('getAccRecord - 1');
  this.getAccRecordResult = result;
  if (result && result.data) {
    console.log('getAccRecord - 2');
    console.log(JSON.stringify(result, null, 4));
    this.accRecord = result;
  }
  else {
    this.accRecord = undefined;
  }
}

accId is an ordinary property of my Javascript class. It works for sysadmin. The Salesforce documentation states:

In the wire adapter’s configuration object, prefix a value with $ to reference a property of the component instance. The $ prefix tells the wire service to treat it as a property of the class and evaluate it as this.propertyName.

I tried the @api decorator for appId, I tried with getters and setters, but result doesn't change, it's never filled.

Once again: this is working for sysadmin, but not for other users, even though they own the object on which LWC is collecting data.

  • My first though given that the user has access to the objects (Account, Opportunity) and it sounds like they have access to the records (via ownership) is to check field level security. One of the fields in ACCOUNT_FIELDS may not be visible to the user? I'm not sure if LWC is smart enough to filter out fields the user can't see or if it just doesn't work at all. – nbrown Mar 23 at 14:00
  • 1
    adding to the @nbrown comment, According to docs If the context user doesn’t have access to a field, an error is returned. If you’re not sure whether the context user has access to a field and you don’t want the request to fail if they don’t, use the optionalFields parameter. – sanket kumar Mar 23 at 14:35
0

The comment by sanket kumar put me on the right track. The other users have access to both the objects (instances/records) and the fields, but... it turns out that one of the fields, a Lookup to another object, is not always filled. For some reason, this is not a problem for a sysadmin, but apparently it is for other users. Which is a bit strange. And of course it sucks that nowhere the browser console tells you that there is a problem, you just don't get any data.

Anyway, using the optionalFields parameter solved my problem, my LWC also works for non sysadmin users.

| improve this answer | |

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.