RestrictionRule defines either a record-access restriction or a default record scope for selected users of an object. Its security meaning depends on enforcementType, not on the metadata type name: Restrict controls which designated records the selected users can access, while Scoping controls the records they see by default without restricting access to records outside that scope.
The rule combines an object, a user-selection expression, a record-selection expression, and an activation setting. A deployed definition is not necessarily in effect: active defaults to false.
Key Elements
| Element | What the Element Controls |
|---|---|
active |
Whether the rule is active. Allowed values are true and false; the default is false. |
enforcementType |
Required. Restrict limits record access; Scoping sets a default record scope without restricting access. Salesforce explicitly says not to use FieldRestrict. The schema also exposes D360_Restrict, but the access semantics and object-support lists below cover only Restrict and Scoping. |
targetEntity |
Required. Identifies the object to which the rule applies. Supported objects depend on enforcementType. Salesforce recommends not changing this value after creation. |
userCriteria |
Required. Selects the users to whom the rule applies, such as users with a particular profile or role. |
recordFilter |
Required. Selects the accessible records for Restrict, or the default record scope for Scoping. |
masterLabel |
Required. The name of the rule. |
description |
Required. Describes the rule. |
version |
Required integer. Records the rule's own version number, not the Metadata API version. |
Behavior and Constraints
Evaluate activation, users, records, and enforcement together
The consequential configuration is the combination of active, enforcementType, targetEntity, userCriteria, and recordFilter. Changing userCriteria changes the affected population. Changing recordFilter changes the records selected for that population.
The same-looking record filter can therefore have different security consequences. With Restrict, it controls accessible records for the selected users. With Scoping, it controls their default record scope; records outside that scope are not made inaccessible by the scoping rule.
Object support depends on the enforcement type
-
Restrict: supports custom objects, external objects,Contract,Event,Quote,Task,TimeSheet, andTimeSheetEntry. -
Scoping: supports custom objects,Account,Case,Contact,Event,Lead,Opportunity, andTask.
Support in one mode does not establish support in the other. Changing enforcementType changes both the rule's security meaning and the object-compatibility requirements. Salesforce recommends not editing targetEntity after creation; this is a recommendation, not a declaration that the element is immutable.
Administrative permissions are separate from rule applicability
Viewing restriction and scoping rules through the API requires View Restriction and Scoping Rules. Viewing, creating, updating, and deleting these rules requires Manage Sharing. These permissions govern inspection and administration of the rule; they are distinct from the users selected by userCriteria.
Expressions can depend on the current user
Documented recordFilter patterns include OwnerId = $User.Id and Department=$User.Department. Documented userCriteria patterns compare $User.ProfileId or $User.UserRoleId with an ID. The actual effect of expressions using current-user values depends on the relevant user and record values, not just on the expression text.
Deployment and Retrieval
RestrictionRule components use the .rule suffix and reside in the restrictionRules folder. In a package.xml manifest, the metadata type name is RestrictionRule; the documented manifest example uses <members>*</members> to select its members.
Check the following when moving a rule between orgs:
-
Activation: a rule definition alone does not establish that the rule is active. Check
active, whose default isfalse. -
Object compatibility: the destination
targetEntitymust be supported for the chosenenforcementType. Do not treat changing the enforcement type as a label-only change. -
Required content: provide
description,enforcementType,masterLabel,recordFilter,targetEntity,userCriteria, and the integerversion. - Org-specific IDs: literal profile or role IDs inside criteria expressions are record IDs, not metadata developer names. In the destination org, those values must identify the intended profiles or roles. Copying the expression unchanged does not establish equivalent user applicability.
- API access: the account inspecting rules through the API needs the rule-viewing permission described above; administration also has the Manage Sharing requirement.
The rule's version is stored in the component. It is separate from the Metadata API version used for deployment or retrieval.
Relationships
targetEntity connects the rule to object metadata represented by CustomObject. Criteria can also contain references inside expressions rather than in separate metadata-reference elements. In particular, profile and role IDs embedded in userCriteria require destination-org interpretation; they are not developer-name references.
References
-
CustomObject:targetEntity.
Reported Issues
-
Record pages and flows reportedly failed instead of returning an expected accessible record when a filter used a formula field. In a 2021 report, an active
Restrictrule on a custom object compared a text formula field with'New Case'and selected users through a custom permission. The affected record page and flow returnedUNKNOWN_EXCEPTION. The reporter attributed the failure to formula-field use in that setup and reported replacing the formula field with a stored text field populated by a record-triggered flow. The reporter cautioned that this workaround is unsuitable for formulas that depend on$User,$Permission, or other current-user context. This is a dated report, not a blanket statement about current formula-field support. See the formula-field failure discussion.
Common Questions
Does RestrictionRule restrict access or just filter the default records?
It can do either. enforcementType=Restrict controls access to designated records for selected users. enforcementType=Scoping sets their default record scope without making records outside that scope inaccessible.
Why is my deployed restriction rule not taking effect?
Check active, which defaults to false, and whether userCriteria selects the user. Also check recordFilter and enforcementType: a scoping rule does not restrict access.
Can Restrict and Scoping use the same objects?
Some objects support both, but the lists differ. For example, Task supports both modes, while Account appears in the scoping list and Contract appears in the restriction list. Check object compatibility whenever changing enforcementType.
Can I copy profile and role IDs in a rule to another org?
Do not assume the copied IDs identify the intended users. Literal IDs in userCriteria are record IDs, not metadata developer names, and must identify the intended profiles or roles in the destination org.
Is the RestrictionRule version the Metadata API version?
No. The required integer version is the rule's own version number. It is separate from the API version used for deployment or retrieval.