0

the main problem i have with this, is that it works well when i'm editing builder as Admin, but when i try to log as specific user, the ID's are not passed within the LWC'c

I will show on example:

First LWC looks like this, which is basically parent

parent LWC

and this is my second LWC, which is basically (another) child

child LWC

anyone got any ideas why this works on System Admin but not on specific profile?

EDIT: added some code snippets apex controller, and yes, user have access to the "Byt__c" object because as shown in first image, he can see the list which consists of "Byt__c" object

public with sharing class DashboardController {

    @AuraEnabled(Cacheable=true)
    public static Byt__c getByt(String bytId) {
        return [SELECT Id, Name, Etapa__c, Vchod__c,slo_ZoBKZ_KZ__c, Ozna_enie__c, Typ__c, Izbovos__c, Account__c
        FROM Byt__c WHERE Id=: bytId LIMIT 1];
    }

this is the "parent" lwc parent.JS has @api flatID; (which i know it holds what ID)

and parrent.HTML

                <c-dashboard
                        flat-i-d={flatID} onstandard={showTemplateOrStandard} onklz={showTemplateOrKLZ}>
                </c-dashboard>
            </lightning-tab> 

CHILD.JS is exposed to that variable - ``` @api flatID;

and in the same class used in that dashboardController 

```  getBytData() {
        console.log("flatid;;;;"+this.flatID);

            getByt({ bytId: this.flatID })
            .then(response => {
                this.bytData = response;

            })
                .catch(error => {
                    console.error(error);
                })
}

i mean, look, i don't there is problem with my code as it works smoothly when System Administrator is logged in, i think the problem is with some security settings in ORG for that specific profile that is disabling correct LWC functionality

3
  • 2
    Is DashboardController with sharing? If so, can the users access to those records? Could you please edit your question adding the code of DashboardController class (copy-paste the code, do not include it as a screenshot)
    – RubenDG
    Commented Aug 10, 2022 at 16:49
  • When adding the code, just add relevant snippets, not the whole component. Make sure to include the component template parts, the component JavaScript class declaration, the relevant @api properties and the functions that are involved in this specific handling. You'll also need to include snippets of any @AuraEnabled methods that are relevant.
    – Phil W
    Commented Aug 10, 2022 at 16:57
  • 1
    RubenDG's comment is still valid; the Apex is with sharing so it is possible that the user does not have sharing access to all the Byt__c records...?
    – Phil W
    Commented Aug 10, 2022 at 21:01

1 Answer 1

2

If a class referenced directly from an LWC is defined as with sharing or inherited sharing Salesforce enforces sharing rules, so Apex code will run in the current user context.
That's why with an administrator you'll be able to query every record, while with a profile that lacks view all data permission or view all on object permission, if the OWD of an object is Private, you'll retrieve only records owned or shared with the user.

So, in order to fix that error, you could either:

  • create a sharing rule (criteria or owner-based) to grant record access to those users
  • change the class definition to without sharing, if you want to let every user with access to DashboardController class query all records.

You can read more on with/without sharing keywords here.

You must log in to answer this question.

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