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
- 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:
- Label—the permission label that appears in permission sets
- Name—the unique name that’s used by the API and managed packages
- Description—optionally, a description that explains what functions the permission grants access to, such as “Approve time-off requests.”
- Connected App—optionally, the connected app that’s associated with this permission
- Click Save.
Assign the custom permission to Profile or Permission Set. Salesforce strongly recommend to use Permission Set and assign user.
- Created custom permission called “NoClosedWonWithoutOPPLI”.
- Created Permission set called “NoClosedWonWithoutOPPLI” (using same name as custom permission) and Added custom permission.
- Assigned my user to Permission Set.
- 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.