Latest Updates

Travel to Technology

Dayton Metro Library

Use Salesforce Custom Permission. Don’t use Profile/User id to skip validation rule.

Salesforce Custom Permission to User to Access Custom Process

Use salesforce custom permission to user to access custom process or apps. Many use case – validation rule should not executed for admin profile or specific user.

Right now admin/developer hard coding profile/user ID or Name in the validation rule to skip. See below

1. Skipping based on Profile Name

AND ( 
  ISCHANGED( OwnerId ), 
   $Profile.Name != 'Admin' 
)

2. Skipping based on Profile Id

AND ( 
    ISCHANGED( OwnerId ), 
    $User.ProfileId != 'ooe12345678990' 
)

Now salesforce introduced “Custom Permission” to avoid hard code Name and ID in validation rule and etc.

Create new custom permission:

From Setup, enter Custom Permissions in the Quick Find box, then select Custom Permissions.

Click New.

Enter the permission information:

Assign the custom permission to Profile or Permission Set. Salesforce strongly recommend to use Permission Set and assign user.

Test Case:
  1. Created custom permission called “NoClosedWonWithoutOPPLI”.
  2. Created Permission set called “NoClosedWonWithoutOPPLI” (using same name as custom permission) and Added custom permission.
  3. Assigned my user to Permission Set.
  4. Now all set. Please see below validation rule
After Customer Permission:
AND( Not($Permission.NoClosedWonWitoutOPPLI), 
Text(StageName) = "Closed Won",
NOT(HasOpportunityLineItem) 
)

In the feature you want to skip this validation rule for more user you can assign permission to that user. That’s it no need to change the validation rule and deployment.

This can be used in Workflow Rule, Process Builder, Flow, Apex Code, Visualforce page.

Reference Resource:

Custom Permission

Demo Video