Examine Person Permissions for Logged-In Person in Lightning Net Element

Final Up to date on July 7, 2022 by Rakesh Gupta

Large Concept or Enduring Query:

  • How one can test whether or not the present person has particular permission (RunReports) or to not customise a part’s habits?


After studying this weblog, you’ll be capable to:

  • Examine commonplace person permission for the present person
  • Examine customized permission for the present person 
  • Customise the part’s habits primarily based on the present person’s permission
  • and far more

Previously written a number of articles on Lightning Net Element. Why not test them out when you are at it?!

  1. Add Lightning Web Components in Mobile and Lightning Experience as Tabs
  2. Create a Form with a Progress Bar in Lightning Web Component

Keegan Watson is working as a Junior Developer at Gurukul on Cloud (GoC). Now she needs to discover ways to test whether or not the present person has RunReports permission or not. 

Examine Permissions

Permissions are the easiest way to manage entry and habits in a Salesforce. When creating Lightning net elements, you possibly can customise a part’s habits primarily based on whether or not the present person has particular permission or not. 

To test whether or not a person has a permission, import Salesforce permissions from the @salesforce/userPermission and @salesforce/customPermission scoped modules and consider whether or not it’s true or undefined. Then if the person has the permission, the part can take a selected motion.

//to test commonplace permission

import hasPermission from '@salesforce/userPermission/PermissionName';

//to test customized permission
import hasCustomPermission from '@salesforce/customPermission/Custom_Permission_Api_Name';

Orgs use namespaces as distinctive identifiers for his or her customization and packages. Customized permissions can embody a namespace. If the customized permission was put in from a managed package deal, prepend the namespace adopted by __ to the permission identify.

Automation Champion Strategy (I-do):

Now it’s time to create a lightning net part to programmatically test RunReports permission in lwc controller. 


A lightning net part can be utilized to construct customized pages for Lightning Expertise and the Salesforce cellular app shortly with point-and-click instruments. Ensure so as to add the best goal for it.

This configuration file makes the part out there for all Lightning web page sorts however restricts assist on desktops.

<?xml model="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://cleaning soap.sforce.com/2006/04/metadata">


A getter is a perform that computes a price for a property. If the person has the RunReports commonplace permission, then the  part will show Person has Permission to Run Experiences message. 

<!-- userPermissionCheck.html -->
    <lightning-card title="Person Permisison Examine Instance">
    <template if:true={isRunReport}>
        <h2>Person has Permission to Run Experiences.</h2>

    <template if:false={isRunReport}>
        <h2>Person Does Not have Permission to Run Experiences.</h2>


This pattern checks whether or not the present person has theRunReports commonplace permission.

// userPermissionCheck.js
import { LightningElement } from 'lwc';
import hasRunReports from '@salesforce/userPermission/RunReports';

export default class PermissionCheck extends LightningElement {
    get isRunReport() {
        return hasRunReports;

Proof of Idea

Formative Evaluation:

I need to hear from you!

What’s one factor you discovered from this publish? How do you envision making use of this new information in the actual world? Be happy to share within the feedback under.

Source link

Thanks for Reading

Enjoyed this post? Share it with your networks.

Leave a Feedback!