Introduction

Permission checking in LWC is a way to control the visibility and functionality of a component based on the permissions of the current user.

This can be done by importing the hasPermission function from the @salesforce/userPermission scoped module and using it to check whether the current user has a specific permission.

This applies to Permission Sets and Custom Permissions too.

How to do it

To check a user’s permission assignment:

  1. Import the permissions from the @salesforce/userPermission  and  @salesforce/customPermission  scoped modules.
import hasPermission from '@salesforce/customPermission/PermissionName';
...

get permissionAssigned(){
	return hasPersmission;
}

Example

The following example imports the hasViewReport function from the @salesforce/customPermission/acme__ViewReport scoped module. This function returns a boolean value indicating whether the current user has the acme__ViewReport permission.

import { LightningElement } from 'lwc';
import hasViewReport from '@salesforce/customPermission/acme__ViewReport';

export default class App extends LightingElement {
    get isReportVisible() {
        return hasViewReport;
    }
}