Home SALESFORCELightning Web Component Summer 20 – Checking User Permissions and Custom Permissions for Lightning Web Components

Summer 20 – Checking User Permissions and Custom Permissions for Lightning Web Components

by Sakthivel Madesh

Summer 20 – Checking User Permissions and Custom Permissions for Lightning Web Components

For this blog post & video described about to Checking User Permissions and Custom Permissions for Lightning Web Components. This feature available from Summer 20 Salesforce Release. we can check User Permissions (Based on Profile access/Permission set access) and Custom Permissions from Lightning Web Components without using Apex Controller (Server side logic),  before Summer 20 to identify the logged in users have access or not using Server side logic’s (i.e apex controller) to using the FeatureManagement.checkPermission, But after Summer 20, there is no need to build logics from Server Side, this can handle from Lightning Web Components controller while importing the @salesforce/userPermission/PermissionName and @salesforce/customPermission/PermissionName from scoped module.

To Identify the logged in Users have any Custom Permission Logic’s using Apex Class: (Before Summer 20)

Boolean hasCustomPermission = FeatureManagement.checkPermission(‘your_custom_permission_api_name’);

To Identify the logged in Users have any Custom Permission Logic’s using Lightning Web Component: (After Summer 20)

import hasPermission from ‘@salesforce/userPermission/PermissionName’;
import hasPermission from ‘@salesforce/customPermission/PermissionName’;
import hasPermission from ‘@salesforce/customPermission/namespace__PermissionName’;

In this video explained about:

  • Created Custom Profile in Salesforce
  • Created Custom Permissions and Enable in Profile Level
  • Create Lightning Web Components and Checked User Permissions
  • Create Lightning Web Components and Checked Custom Permissions
  • Administrators Can Log in as Any User from Login Access Policies
  • Profile Objects and Fields
  • Profiles Access in Salesforce
  • Disable the Lightning Web Component Button based on the Profile Permission and Custom Permission

Lightning Web Component Button to Enable based on the following access:
Send => View Setup and Configuration
Send Email => Send Email
Send SMS => Custom Permission (Send SMS)

import hasViewSetup from “@salesforce/userPermission/ViewSetup”; //View Setup and Configuration
import hasEmailSingle from “@salesforce/userPermission/EmailSingle”; //Send Email
import hasSendSMS from “@salesforce/customPermission/Send_SMS”; //Custom Permission (Send SMS)
LWC HTML:
<template>
    <lightning-card title=”Demo 30 – User & Custom Permissions” icon-name=”action:script”>
        <h1>User Permissions & Custom Permissions</h1>
            <lightning-button
                label=”Send”
                icon-name=”utility:setup”
                disabled={disableSendBtn}
                variant=”brand”>
            </lightning-button>
            <lightning-button
                label=”Send Email”
                disabled={disableSendEmailBtn}
                icon-name=”utility:email”
                variant=”brand”>
            </lightning-button>
            <lightning-button
                label=”Send SMS”
                disabled={disableSendSMSBtn}
                icon-name=”utility:new_direct_message”
                variant=”brand”>
            </lightning-button>
    </lightning-card>
</template>

LWC JS:

import { LightningElement } from ‘lwc’;
import hasViewSetup from “@salesforce/userPermission/ViewSetup”;
import hasEmailSingle from “@salesforce/userPermission/EmailSingle”;
import hasSendSMS from “@salesforce/customPermission/Send_SMS”;
export default class Demo30GetPermissions extends LightningElement {
    get disableSendBtn() {
        return !hasViewSetup;
    }
    get disableSendEmailBtn() {
        return !hasEmailSingle;
    }
    get disableSendSMSBtn() {
        return !hasSendSMS;
    }
}

About Custom Permissions in Salesforce:
Custom permissions a way to provide access to custom processes or apps. After we created a custom permission and we can associated it with a process or app, you can enable the permission in permission sets/profile levels.

https://help.salesforce.com/articleView?id=perm_sets_custom_perms.htm&type=5
https://help.salesforce.com/articleView?id=custom_perms_overview.htm&type=5

Please check the below video for more info about Summer 20 – Checking User Permissions and Custom Permissions for Lightning Web Components:

Reference Links:

https://releasenotes.docs.salesforce.com/en-us/summer20/release-notes/rn_lwc_access_permissions.htm

https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_profile.htm

You may also like

Leave a Comment