Newer Version Available

This content describes an older version of this product. View Latest

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.

This feature is a Beta Service. Customer may opt to try such Beta Service in its sole discretion. Any use of the Beta Service is subject to the applicable Beta Services Terms provided at Agreements and Terms.

Note

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>52.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.