Using Custom Permissions With Lightning Component Visibility
I love custom permissions. I believe they may be the most flexible feature within Salesforce.
Lightning experience admins out there are likely familiar with component visibility. It is the ability for a page to hide or display a component on the page based on some criteria.
At Dreamforce 18, Salesforce announced lightning pages. This adds even more custom pages by hiding and displaying fields based on criteria. This means you could potentially have a one-page layout with all the differences being controlled by component visibility criteria. No more tons of different page layouts by profile!
This change does cause a complication. It will increasingly get more difficult to know why a given user can or cannot see something on the page. Oh what is a Salesforce Admin to do?
The Issue with Lightning Component Visibility
Before we dive into a better solution, let’s take a look at a simple example of why Component visibility on Salesforce Lightning pages is a potential headache.
With Lightning Component Visibility, we can decide if the component will display on the page for the user based on some set of criteria. Common practice is based on the user’s profile or username. The example we have here is actually pretty simple. It’s referencing only two profiles and a single username. This could have even more criteria and more complicated logic. You can imagine how more complicated these component visibility criteria have the potential to become.
Why do I hate this setup for Lightning Component Visibility? Close your eyes, well actually don’t because you’re reading this. Imagine the scenario. It’s late Friday afternoon. You’re eager to shut down and go home for the weekend, maybe for a favorite meal or hobby. Right before you’re about to close the laptop, the CEO pops his head in, cradling his “best boss” coffee mug and asks “Before you leave, when the CFO looks at this page he sees all this information and I don’t. Plus, the CFO can’t see the same dashboard as I see even though we’re looking at the same page. Can you tell me why? That’ll be great?”
Ugh. In classic, we would check record types and page layouts, Field Level Security and profiles. With Lightning Component it could be due to one of the above options PLUS the component visibility logic. Heaven forbid if your logic is complicated that you have to spend ten or more minutes trying to figure this out.
We can do better. Way better.
The Joy of Custom Permissions
We’ve seen what a headache using Component Visibility criteria can be. Let’s look at a more simple solution.
Take a look at this example.
One item in the criteria. That’s it.
Why is this better? Not only is the component visibility criteria significantly simpler, but it’s also easier to determine who can see it. Custom Permissions can be assigned to a user through a Permission Set or directly to a profile. All you need to do is name your Custom Permission and/or Permission Set to mirror what the Lightning Component is. All we have to do then is look at the Permission Sets assigned to the user and the Custom Permissions assign to their profile. Boom! We can clearly see that this particular user can see Dashboard 1, Dashboard 2, and Time Card Flow Access. No need to open the Lightning page.
What if we need to make a change to visibility? No worries. We either add or remove a custom permission from the user. No need to mess around with the Lightning Page. No need to confirm the Lightning Component Visibility criteria logic. Just update the Custom Permission and you’re done!
Creating Custom Permissions
Let’s take a look at how we create a Custom Permission. Prepare yourself. It takes a lot of work.
- Open Setup
- Use quick find to filter to Custom Permission and click
- Click New
- Enter a Label & Name
- Click Save
Oh, the humanity! So much work.
Assigning the Custom Permission for Lightning Component Visibility
It’s easy to use a Custom Permission for Lightning Component Visibility. In the Lightning App Builder, click on the component and then click “Add Filter” Then we click “Select” and we’ll see a pop up screen.
When the screen first displays, we choose “Permissions” from the drop down menu which will display a new drop down.
From the second drop down, we choose “Custom Permissions.”
Finally, we choose the Custom Permission from the list of available permissions and click “Done.”
They’re also a savior to the Salesforce Admin on a Friday night attempting to determine why a user can see or not see something on a Lightning Page.
Are you using Custom Permissions? How else are you using them?
Don’t miss a post! Sign up to receive email notications.
I run this site, the podcast, and my training videos for the community. I do incur some costs. I greatly appreciate if you can help me out by checking out my affiliates and – if you shop amazon – start your search on my site.