How to check for Permission Sets in Validation Rule

by Sudipta Deb | Jul 29, 2020 | configuration, Custom Permission, Permission Set, Salesfor, Validation Rule | 1 comment

Recently while dealing with one of the requirement for my current project, I need to check for logged in user’s persona and based on that, write validation rules which will restrict them to do some operations.

Here is the requirement

Let’s say we have two personas – Change User and Change Manager. Both Change User and Change Manager can view and edit the cases, but when the case is in “In Progress” state, Change User is not allowed to update the target resolution date on the case.

Setup

Both the personas – Change User and Change Manager share the same role in the role hierarchy. (I know realistically they should have different role, but in my scenario, this is what customer wants as it aligns with their organization structure). So the way to differentiate them is through permission set. As a result, I have created two permission sets – Change User and Change Manager. Assigned the permission sets to respective users. 
“In Progress” is a case status value and Target resolution date is a custom field on Case object.

Problem faced

To implement the requirement that “Change User is not allowed to update the target resolution date on the case when the case is in In Progress state“, I need to write validation rule. But there is no way that you can check for logged in user’s assigned permission set in validation rule. There is a Salesforce Idea open for this feature. So makes sense that you vote for this idea.

Solution

I have created two Custom Permissions – Change User and Change Manager. Yes with the same name, but name doesn’t matter, I choose to give the same name to make life simpler. 😊Then I added these custom permissions into the corresponding permission sets like Change User ( Custom Permission ) will go into  Change User ( Permission Set) and Change Manager ( Custom Permission ) will go into  Change Manager ( Permission Set).
With that done, I referred these custom permissions in my validation rule ( Yes, we can refer custom permissions in Validation Rule) like below –
I hope this will help you if you are also facing the same problem. I am very much interested to know if you have some other cool tricks to handle this situation. Thank you.

Written by

Related Posts

Restrict Uploading Files In Salesforce

Restrict Uploading Files In Salesforce

While working in Salesforce, we sometimes come up with the requirements where we need to build some sort of validation to restrict uploading files with specific extensions or in other words, allow only approved file types/extensions. This is very important because uploading executing or javascript code can bring potention security concerns by exposing internal data to outside world.

So allowing only certain type of files for upload is a very common requirement. In this blog post, I am sharing couple of solutions with pros and cons to implement this requirement.

read more...

1 Comment

  1. Unknown

    Thank you, Sudipta, I wasn't aware of this approach!

    Reply

Leave a Reply