Step By Step Guide to Using Restriction Rules in Salesforce
Traditionally, to control the visibility of records in Salesforce, we used to start with the most restrictive setting (i.e., setting OWD to Private for an object) and then open up access using various features like role hierarchy, sharing rules, teams, etc.
Consider the following diagram. Before Restriction Rules, we started with the most restrictive setting and then opened up access using various features.
Image Source: Restriction Rule Developer Guide
But now, with the Winter ’22 Release of Salesforce, we can also define a rule to restrict the visibility of records. For example, even if we have defined the OWD to Public Read or Public Read/Write on an object, we can now add Restriction Rules to hide certain records from certain users.
Image Source: Restriction Rule Developer Guide
So, What Are Restriction Rules?
Restriction Rules allow admins to restrict the visibility of selected records from a selected group of users. It went GA (Generally Available) in Salesforce Winter ’22 Release.
Which Objects are Supported for Restriction Rules?
As of now, only the following objects are supported for Restriction Rules:
Custom Objects
Contracts
Events
Tasks
Time Sheets
Timesheet Entries
Where are Restriction Rules Applied?
Once defined, Restriction Rules are applied to the following Salesforce features:
List Views
Lookups
Related Lists
Reports
Search
SOQL
SOSL
What are the Current Limitations & Considerations for Restriction Rules?
Only two Restriction Rules can be created on the supported objects in Enterprise Edition & five in Unlimited & Performance Edition
Only the following data types are supported in the recordFilter and userCriteria fields:
Boolean
Date
DateTime
Double
Int
Reference
String
Time
Restriction Rules support only the EQUALS operator. The AND, OR, or any other operators aren’t supported.
The use of formulas isn’t supported.
You can use a change set to move Restriction Rules from one org to another.
If you include IDs in your recordFilter or userCriteria fields that are specific to your Salesforce org (such as a role, record type, or profile ID), you must modify these IDs in the target org if they’re different from the org where the Restriction Rules were originally created.
OK, that's enough talk. Now, let's take a look at Restriction Rules in action in just under 10 minutes.
References & Useful URLs
Post from Salesforce Engineering (10 mins) - Restriction Rules: Complementing Salesforce’s Record Access Control Mechanism (we all know Salesforce sharing works by creating records in a “Share” object for each main object in Salesforce. This post lets you look under the hood to understand how Restriction Rules work.)
Blog Post (15 mins) - #22 Ways to Share Records in Salesforce