Custom Flow Error For the Win!
May 12, 2024This week a client of mine had a requirement to prevent their users from deleting tasks.
You may know that the ability to create, edit, and delete tasks are bundled together in a single permission at the profile level.
If we want to take away one of those permissions, users lose them all (which in this case they absolutely needed).
What to do?
Enter the Salesforce Flow Custom Error component (and new Custom Permission of our own).
First, we'll create a custom permission named "Delete Tasks" and assign it to a new permission set we created for this requirement.
With this done, we now have the ability to assign that new custom permission (Delete Tasks) to anyone by using the permission set.
This is key, because it unlocks a cool feature in the Flow Builder, as you'll soon see.
We'll next create a Record-Triggered Flow designed to fire when a Task record is deleted.
We'll choose that the Formula Evalutes to True in the condition requirement so the Flow only fires when our condition (which we're about to set) is true.
And this is where the cool feature I mentioned comes into play. By using Formula Evaluates to True we can check if the current user has our custom Delete Tasks permission.
Just click on Insert a Resource and select the Permission option from the list.
This will show you all the Custom Permissions in the environment you're in. In this environment there are two, but we'll just select the one we need (Delete Tasks).
Click once and that permission will appear in the Formula Editor.
Wrap the formula in a NOT() statement.
This tells Salesforce we only want the Flow to run when the current running user does not have this permission i.e. they aren't allowed to delete tasks.
Final step is to add the Custom Error element to the canvas and set the error message.
With that done we can save and activate our Flow.
With the Flow now active, it will run whenever a Task is deleted.
If the user doesn't have the permission set, it will throw the error, otherwise nothing will happen and they can delete the task.
And that's how I was able to separate the delete task permission from everything else.
Hope this helps!
Best,
Nick
SalesforceĀ Saturdays
Join the Salesforce Saturday newsletter. Every Saturday, you'll get 1 actionable tip on Salesforce technology or career growthĀ related to the Salesforce Industry.
We hate SPAM. We will never sell your information, for any reason.