-1

I have a LWC that loads in data by calling an Apex class with a SOQL query. It works when I am testing to view logged is as a system administrator, but when I try to view it logged in as another user, the data doesn't load in.

@wire(getData, { accountId: '$recordId'}) 
    wireHandler({data,error}) {
        if(data) {
            //code
        } 
    }

When I view the console the error prints, but I don't know how to approach fixing this because all it gives me is taking me to an error..

6
  • What is the code for getLoanApplications()? Do your Apex logs show an exception being thrown?
    – David Reed
    Jun 23, 2021 at 19:53
  • 2
    What's the Org-Wide Default for Loan_Application__c and the sharing mode of the controller class? Or, another way, does the user actually have record-level access to this object?
    – David Reed
    Jun 23, 2021 at 20:23
  • 2
    Does the other user's profile have access to the apex class? You say the error prints, but what does it show if instead of console.log('error');, you add in the actual error returned console.log('error ' + error); Jun 23, 2021 at 21:57
  • Please edit your post to include the details mentioned by David and Kris. Jun 23, 2021 at 23:41
  • In the UI, go to Setup --> apex classes --> find your apex class and you should see Security button next to it. Click it and see if the user's profile is on the enabled side. In terms of the console, try console.log('error ' + error.body.message);. Jun 24, 2021 at 0:35

1 Answer 1

1

Since Winter '21, users need access to the apex class of @AuraEnabled apex methods based on their profile.

For future reference, if you appropriately handle/display the error message returned from the wire - it would have told you the issue.

Instead of simply doing

console.log('error')

which only tells you that it went into the error path, you can actually display the message returned which, in this case, would've been along the lines of

You do not have access to the Apex class named xxxxx.

console.log(error.body.message);

There's also this reduceErrors method showcased in the lwc-recipes that is useful for reuse to handle scenarios with more than one error.

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