3

I am just going through the Summer 20 Release Notes and found an article - Check User Permissions for Lightning Web Components

Here is the link

Here I found, to check View Setup permission you just have to import ->

import hasViewSetup from '@salesforce/userPermission/ViewSetup';

I just want to know is there any User permission to check Edit Access so that I can import directly and use in My LWC.

2

No, as there's already a solution available: getObjectInfo.

Here's the example from the documentation:

import { LightningElement, wire } from 'lwc';
import { getObjectInfo } from 'lightning/uiObjectInfoApi';
import ACCOUNT_OBJECT from '@salesforce/schema/Account';

export default class Example extends LightningElement {
    @wire(getObjectInfo, { objectApiName: ACCOUNT_OBJECT })
    propertyOrFunction;
}

Since it's a wire method, this is actually reactive, in case the permissions change for some reason, your component will be notified of the change in permissions without having to reload the component.

| improve this answer | |
  • I have to restrict user to enter in input field if the user does not have access to that field and without using apex, is this possible only in LWC? – Sahil Malhotra Jun 26 at 12:39
  • @SahilMalhotra Yes, the ObjectInfo response includes the fields and their editability. – sfdcfox Jun 26 at 13:01
  • Also, check this out, I have tried exploring getObjectInfo deep : - OBJECT INFORMATION IN LIGHTNING WEB COMPONENT – sanket kumar Jun 26 at 14:47
  • Hi all, I checked with getObjectInfo but did not get the name that checks the Editability of fields. I have checked with admin profile and other profile who do not have access to that field, but nothing change in wired result. So please tell me from which I can check the editability of field so I can restrict the user to access the field in LWC – Sahil Malhotra Jun 29 at 5:10

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.