Create the Restriction Rule Using the Metadata API

Create a restriction rule that controls which tasks members of the Sales Team can access using the RestrictionRule Metadata API type.

Where possible, we changed noninclusive terms to align with our company value of Equality. We maintained certain terms to avoid any effect on customer implementations.

Important

Available in: Lightning Experience in Enterprise, Performance, Unlimited, and Developer Editions

User Permissions Needed
To create and manage restriction rules: Manage Sharing
To view restriction rules: View Setup & Configuration AND View Restriction and Scoping Rules

You can create up to two restriction rules per object in Enterprise and Developer Editions and up to five restriction rules per object in Performance and Unlimited Editions.

  1. Set up the package.xml manifest file and your directory.

    Example package.xml file:

    1<?xml version="1.0" encoding="UTF-8"?>
    2<Package xmlns="http://soap.sforce.com/2006/04/metadata">
    3  <types>
    4    <members>*</members>
    5    <name>RestrictionRule</name>
    6  </types>
    7  <version>55.0</version>
    8</Package>

    Example directory:

    1myPackage/package.xml
    2myPackage/restrictionRules
    3myPackage/restrictionRules/Rule1.rule
    4myPackage/restrictionRules/Rule2.rule
  2. Include all required fields. For more information, see the reference topic RestrictionRule.

    For our example, we set the fields as follows:

    1<?xml version="1.0" encoding="UTF-8"?>
    2<RestrictionRule xmlns="http://soap.sforce.com/2006/04/metadata">
    3  <active>true</active>
    4  <description>Sales team can see only task records with specified record type</description>
    5  <enforcementType>Restrict</enforcementType>
    6  <masterLabel>Sales Team Record Type</masterLabel>
    7  <recordFilter>recordTypeId = '011xxxxxxxxxxxx'</recordFilter>
    8  <targetEntity>Task</targetEntity>
    9  <userCriteria>$User.ProfileId = '00exxxxxxxxxxxx'</userCriteria>
    10  <version>1</version>
    11</RestrictionRule>
  3. Zip your directory and deploy your changes. For more information, see Deploying and Retrieving Metadata in the Metadata API Developer Guide.
  4. Note the ID returned for the newly created restriction rule for later reference.