Permissions serve as a standard method to regulate access and actions within a Salesforce organization. When creating Lightning web components, you have the flexibility to tailor a component’s behavior based on whether the current user possesses a specific permission.
To verify if a user holds a permission, you can import Salesforce permissions from the scoped modules @salesforce/userPermission and @salesforce/customPermission, and then assess whether the permission is true or undefined. Subsequently, if the user possesses the permission, the component can execute a designated action.
Custom permissions may include a namespace. Organizations utilize namespaces as distinctive identifiers for their customizations and packages. If the custom permission originates from a managed package, append the namespace followed by __ to the permission name.
Example of a Standard Permission:
import hasPermission from '@salesforce/userPermission/StandardPermissionName';
Examples of Custom Permissions:
import hasPermission from '@salesforce/customPermission/CustomPermissionName';
import hasPermission from '@salesforce/customPermission/namespace__CustomPermissionName';
You have the freedom to choose the name of the static reference. In these examples, the format “hasPermission” was selected to signify that the reference holds a Boolean value.