---
schema_version: "1"
id: becd55b457f32e2f3387bb52b691c70e055226909d9ea7829c93eb9434cc7bb0
title: Territory2Rule
collection: legacydeveloper
version: current
locale: en-us
portal_url: https://docs.salesforce.com/legacydeveloper/current/en-us/api_meta/meta_territory2rule.md
canonical_url: https://developer.salesforce.com/docs/atlas.en-us.api_meta.meta/api_meta/meta_territory2rule.htm
source_site: developer.salesforce.com
content_type: documentation
content_hash: 11bdfc481b2afef0e3a331400078514cc92f7704a5b29b03f8a3b11448056ec9
description: Represents the metadata associated with a territory assignment rule associated with an object, such as Account. Available if Sales Territories has been enabled.
---
# Territory2Rule

Represents the metadata associated with a territory assignment rule associated with an object, such as Account. Available if Sales Territories has been enabled.

This type extends the [Metadata](https://developer.salesforce.com/docs/atlas.en-us.api_meta.meta/api_meta/metadata.htm "The base class for all metadata types. You can’t edit this object. A component is an instance of a metadata type.") metadata type and inherits its fullName field.

## File Suffix and Directory Location

Territory2Rule components have the suffix territory2Rule and are stored in the rules folder under the folder for the corresponding Territory2Model.

## Version

Territory2Rule components are available in API version 32.0 and later.

## Special Access

The Territory2Model object has a State field in SOAP API. States include Planning, Active, Archived, and several other states, such as Cloning, that indicate that a process is underway. Users who don’t have the Manage Territories permission can access rules that belong to the model in Active state. The Manage Territories permission is required for deploy() calls for all territory management entities, in addition to the permissions required by Metadata API. Using retrieve() without the Manage Territories permission returns only entities that belong to a Territory2Model in Active state. We recommend against retrieving without the Manage Territories permission because the call retrieves only partial data.

The SOAP API and the user interface require that a user attempting to create or edit a rule has field-level security access to the fields referenced in the rule item. This restriction is relaxed for Metadata API deploy() operations, as they require both Manage Territories and either the Modify Metadata Through Metadata API Functions or Modify All Data permissions.

## Fields

| Field Name | Field Type | Description |
| --- | --- | --- |
| active | boolean | Required. Indicates whether the rule is active (true) or inactive (false). Via the API, active rules run automatically when object records are created and edited. The exception is when the value of the IsExcludedFromRealign field on an object record is true, which prevents record assignment rules from evaluating that record. |
| booleanFilter | string | An advanced filter condition. For example: (1 AND 2) OR 3. Numbering must start at 1 and must be contiguous. |
| name | string | Required. The user interface label for the rule. |
| objectType | string | Required. The object that the rule is defined for. For API version 32.0, the only available object is Account. |
| ruleItems | [Territory2RuleItem](#Territory2RuleItem) | The items that define a rule’s the selection criteria, such as Billing State equals California. |

## Territory2RuleItem

Represents the association of a rule item to a rule. Available in API version 32.0 and later.

<table class="featureTable sort_table" summary="">



          <thead class="thead sorted" align="left">
            <tr>
              <th class="featureTableHeader  " id="d897813e265">Field Name</th>

              <th class="featureTableHeader  " id="d897813e268">Field Type</th>

              <th class="featureTableHeader  " id="d897813e271">Description</th>

            </tr>

          </thead>

          <tbody class="tbody">
            <tr>
              <td class="entry" headers="d897813e265" data-title="Field Name"><span class="keyword parmname">field</span></td>

              <td class="entry" headers="d897813e268" data-title="Field Type">string</td>

              <td class="entry" headers="d897813e271" data-title="Description">The standard or custom object field that the rule item operates on.</td>

            </tr>

            <tr>
              <td class="entry" headers="d897813e265" data-title="Field Name"><span class="keyword parmname">operation</span></td>

              <td class="entry" headers="d897813e268" data-title="Field Type">FilterOperation (<a class="xref" href="https://developer.salesforce.com/docs/atlas.en-us.api_meta.meta/api_meta/meta_objects_intro.htm#enumeration_title">enumeration</a> of type string)</td>

              <td class="entry" headers="d897813e271" data-title="Description">The criterion to apply for the rule item. For example:
                <kbd class="ph userinput">equals</kbd> or <kbd class="ph userinput">starts with</kbd>. Valid values
                are: <ul class="ul bulletList">
                  <li class="li"><samp class="codeph soql">equals</samp></li>

                  <li class="li"><samp class="codeph soql">notEqual</samp></li>

                  <li class="li"><samp class="codeph soql">lessThan</samp></li>

                  <li class="li"><samp class="codeph soql">greaterThan</samp></li>

                  <li class="li"><samp class="codeph soql">lessOrEqual</samp></li>

                  <li class="li"><samp class="codeph soql">greaterOrEqual</samp></li>

                  <li class="li"><samp class="codeph soql">contains</samp></li>

                  <li class="li"><samp class="codeph soql">notContain</samp></li>

                  <li class="li"><samp class="codeph soql">startsWith</samp></li>

                  <li class="li"><samp class="codeph soql">includes</samp></li>

                  <li class="li"><samp class="codeph soql">excludes</samp></li>

                  <li class="li">
                    <samp class="codeph soql">within</samp> (<samp class="codeph nolang">DISTANCE</samp> criteria only)
                  </li>

                </ul>
              </td>

            </tr>

            <tr>
              <td class="entry" headers="d897813e265" data-title="Field Name"><span class="keyword parmname">value</span></td>

              <td class="entry" headers="d897813e268" data-title="Field Type">string</td>

              <td class="entry" headers="d897813e271" data-title="Description">The field value or values to evaluate. For example: if the field is
                <span class="keyword parmname">Billing ZIP/Postal Code</span>, a value could be
                <samp class="ph systemoutput">94105</samp>.
              </td>

            </tr>

          </tbody>

        </table>

## Declarative Metadata Sample Definition

The following example shows the definition of a Territory2RuleItem component.

<?xml version="1.0" encoding="UTF-8"?>
<Territory2Rule xmlns="http://soap.sforce.com/2006/04/metadata">
    <label\>Northern CA</label\>
    <description\>To capture northern CA based accounts</description\>
    <objectType\>Account</objectType\>
    <active\>True</active\>
    <ruleItems\>
        <field\>BillingZip</field\>
        <operation\>contains</operation\>
        <value\><94105,94404,94536/value>
    </ruleItems\>
    <ruleItems\>
        <field\>Industry</field\>
        <operation\>equals</operation\>
        <value\>IT</value\>
    </ruleItems\>
    <ruleItems\>
        <field\>someCustomField\_\_c</field\>
        <operation\>greater\_than</operation\>
        <value\>50000</value\>
    </ruleItems\>
    <booleanFilter\>(1 OR 2) AND 3</booleanFilter\>
</Territory2Rule\>

The following is a package.xml sample. FY13 and FY14 represent names of territory models and demonstrate that rules can have _identical_ developer names within _different_ models. A wildcard character (\*) in place of the model name can be used to retrieve all rules in all models in an org.

<?xml version="1.0" encoding="UTF-8"?> 
<Package xmlns="http://soap.sforce.com/2006/04/metadata"> 
        <types\> 
            <members\>FY13</members\>
            <members\>FY14</members\> 
            <name\>Territory2Model</name\> 
        </types\>
        
        <types\>
            <members\>FY13.AccRule1</members\>
            <members\>FY14.AccRule1</members\>
            <name\>Territory2Rule</name\>
        </types\>
        
        <version\>68.0</version\>
</Package\>

## Usage

- A territory rule can have up to 10 rule items.
- The sort order of rule items is implicitly derived from the position of the rule items in the XML
- Rules can’t be run via Metadata API.
- Territory Management 2.0 components don’t support packaging or change sets and aren’t supported in [CRUD calls](https://developer.salesforce.com/docs/atlas.en-us.api_meta.meta/api_meta/meta_crud_based_calls_intro.htm "Use CRUD-based calls to work with metadata components in a manner similar to how synchronous API calls in the enterprise WSDL act upon objects.").

## Wildcard Support in the Manifest File

This metadata type supports the wildcard character \* (asterisk) in the package.xml manifest file. For information about using the manifest file, see [Deploying and Retrieving Metadata with the Zip File](https://developer.salesforce.com/docs/atlas.en-us.api_meta.meta/api_meta/file_based_zip_file.htm "The deploy() and retrieve() calls are used to deploy and retrieve a .zip file. Within the .zip file is a project manifest (package.xml) that lists what to retrieve or deploy, and one or more XML components that are organized into folders.").