---
schema_version: "1"
id: a4d198c26fc7f6cb7244cfe3650b8f70ad49b5951746907f0308a7b5cea6587f
title: Territory2
collection: legacydeveloper
version: current
locale: en-us
portal_url: https://docs.salesforce.com/legacydeveloper/current/en-us/api_meta/meta_territory2.md
canonical_url: https://developer.salesforce.com/docs/atlas.en-us.api_meta.meta/api_meta/meta_territory2.htm
source_site: developer.salesforce.com
content_type: documentation
content_hash: 13dbf63b0afebeb0873e50e9da97a45f438265447a885b0ffeda3f2b932d55c8
description: Represents the metadata associated with a sales territory. This type extends the Metadata metadata type and inherits its fullName field. Available if Sales Territories has been enabled.
---
# Territory2

Represents the metadata associated with a sales territory. This type extends the Metadata metadata type and inherits its fullName field. Available if Sales Territories has been enabled.

## File Suffix and Directory Location

Territory2 components have the suffix territory2 and are stored in the territories folder under the folder for the corresponding Territory2Model.

## Version

Territory2 components are available in API version 32.0 and later.

## Special Access Rules

The Territory2Model object has a State field in the SOAP API. States include Planning, Active, Archived, and several other states, such as Cloning, that indicate that a process is underway. Users who do not have the Manage Territories permission can access territories that belong to the model in Active state. The Manage Territories permission is required for deploy() calls for all territory management entities. 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.

## Fields

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



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

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

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

            </tr>

          </thead>

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

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

              <td class="entry" headers="d895357e129" data-title="Description">Specifies whether users in this territory can access accounts that are assigned
                to this territory and are otherwise inaccessible. Valid values are:<ul class="ul bulletList">
                  <li class="li"><samp class="codeph nolang">Read</samp></li>

                  <li class="li"><samp class="codeph nolang">Edit</samp></li>

                  <li class="li"><samp class="codeph nolang">All</samp></li>

                </ul>
                If your organization’s sharing model for accounts is Public Read/Write, valid
                values are only <samp class="codeph nolang">Edit</samp> and <samp class="codeph nolang">All</samp>. If no value is set for this field, this field
                value uses the default access level that is specified in Territory2Settings as
                permitted by the organization’s sharing settings.</td>

            </tr>

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

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

              <td class="entry" headers="d895357e129" data-title="Description">Specifies whether users in this territory can access cases that are assigned to
                this territory and are otherwise inaccessible. Valid values are:<ul class="ul bulletList">
                  <li class="li"><samp class="codeph nolang">None</samp></li>

                  <li class="li"><samp class="codeph nolang">Read</samp></li>

                  <li class="li"><samp class="codeph nolang">Edit</samp></li>

                </ul>
                Specify no value if your organization’s sharing model for cases/opportunities
                is Public Read/Write. If no value is set for this field, this field value uses the
                default access level that is specified in Territory2Settings as permitted by the
                organization’s sharing settings.</td>

            </tr>

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

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

              <td class="entry" headers="d895357e129" data-title="Description">Specifies whether users in this territory can access contacts that are assigned
                to this territory and are otherwise inaccessible. Valid values are:<ul class="ul bulletList">
                  <li class="li"><samp class="codeph nolang">None</samp></li>

                  <li class="li"><samp class="codeph nolang">Read</samp></li>

                  <li class="li"><samp class="codeph nolang">Edit</samp></li>

                </ul>
                Specify no value if your organization’s sharing model for contacts is Public
                Read/Write or Controlled By Parent.</td>

            </tr>

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

              <td class="entry" headers="d895357e126" data-title="Field Type">FieldValue</td>

              <td class="entry" headers="d895357e129" data-title="Description">Values for custom fields defined on the Territory2 object and used by this
                territory. Their metadata is captured separately in CustomObject. Note the
                following:<a name="t2_t2m_custom_fields_def"><!-- --></a>
                <ul class="ul bulletList" id="t2_t2m_custom_fields_def">
                  <li class="li">Territory2 and Territory2Model objects do not handle values for Text Area
                    (Long), Text Area (Rich), and text-encrypted custom fields.</li>

                  <li class="li">Fields are referenced using their API names. Compound field types like
                    Location appear as their constituent column fields. For example,
                    <span class="keyword parmname">nnn_Latitude__s</span>, <span class="keyword parmname">nnn_Longitude__s</span>
                    where “nnn” is the field name and the suffixes are the geolocation
                    components.
                  </li>

                  <li class="li">Values of required custom fields are enforced during the <samp class="codeph nolang">deploy()</samp> operation.</li>

                </ul>
              </td>

            </tr>

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

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

              <td class="entry" headers="d895357e129" data-title="Description">A description of the territory.</td>

            </tr>

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

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

              <td class="entry" headers="d895357e129" data-title="Description">Required. The user interface label for the territory.</td>

            </tr>

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

              <td class="entry" headers="d895357e126" data-title="Field Type">Territory2AccessLevel</td>

              <td class="entry" headers="d895357e129" data-title="Description">Represents the user access levels of an object associated to a territory.
                Available in API version 57.0 and later.</td>

            </tr>

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

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

              <td class="entry" headers="d895357e129" data-title="Description">Specifies whether users in this territory can access opportunities that are
                assigned to this territory and are otherwise inaccessible. Valid values are: <ul class="ul bulletList">
                  <li class="li"><samp class="codeph nolang">None</samp></li>

                  <li class="li"><samp class="codeph nolang">Read</samp></li>

                  <li class="li"><samp class="codeph nolang">Edit</samp></li>

                </ul>
                Specify no value if your organization’s sharing model for cases/opportunities
                is Public Read/Write. If no value is set for this field, this field value uses the
                default access level that is specified in Territory2Settings as permitted by the
                organization’s sharing settings.</td>

            </tr>

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

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

              <td class="entry" headers="d895357e129" data-title="Description">The name of the territory’s parent. When you specify the parent territory, use
                the developer name. Do not use the “fully qualified” name. Custom fields with no
                values are retrieved with values of type: <samp class="codeph nolang"> &lt;value
                  xsi:nil="true"/&gt;</samp>. You can also use <samp class="codeph nolang"> &lt;value
                  xsi:nil="true"/&gt;</samp> syntax to remove existing values in custom fields.
              </td>

            </tr>

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

              <td class="entry" headers="d895357e126" data-title="Field Type">Territory2RuleAssociation[]</td>

              <td class="entry" headers="d895357e129" data-title="Description">Represents an object assignment rule and its association to a territory. Use
                the developer name of the rule.</td>

            </tr>

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

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

              <td class="entry" headers="d895357e129" data-title="Description">Required. The territory type that the territory belongs to.</td>

            </tr>

          </tbody>

        </table>

## FieldValue

Represents the values of custom fields on the Territory2 object. Available in API version 32.0 and later.

| Field Name | Field Type | Description |
| --- | --- | --- |
| name | string | Required. The user interface label for the territory. |
| value | any type | The value of the field, which can also be null. The field type is specified in the XML and depends on the field value. |

## Territory2AccessLevel

Represents the association of an object access level to a territory. Available in API version 57.0 and later.

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



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

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

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

            </tr>

          </thead>

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

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

              <td class="entry" headers="d895357e474" data-title="Description">Required. Valid values are:<ul class="ul bulletList">
                  <li class="li"><samp class="codeph nolang">Read</samp></li>

                  <li class="li"><samp class="codeph nolang">Edit</samp></li>

                  <li class="li"><samp class="codeph nolang">Transfer</samp></li>

                  <li class="li"><samp class="codeph nolang">All</samp></li>

                </ul>
                If your organization’s sharing model for accounts is Public Read/Write, valid
                values are only <samp class="codeph nolang">Edit</samp> and <samp class="codeph nolang">All</samp>. If no value is set for this field, this field
                value uses the default access level that is specified in Territory2Settings as
                permitted by the organization’s sharing settings. </td>

            </tr>

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

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

              <td class="entry" headers="d895357e474" data-title="Description">Required. The type of object associated to the territory. For example,
                Lead.</td>

            </tr>

          </tbody>

        </table>

## Territory2RuleAssociation

Represents the association of an object assignment rule to a territory. 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="d895357e558">Field Name</th>

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

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

            </tr>

          </thead>

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

              <td class="entry" headers="d895357e561" data-title="Field Type">boolean</td>

              <td class="entry" headers="d895357e564" data-title="Description">Required. Indicates whether the rule is inherited from a parent territory
                (<samp class="codeph nolang">true</samp>) or local to the current territory
                (<samp class="codeph nolang">false</samp>).<p class="p">Rule inheritance flows from the
                  parent territory where the rule is created to the rule’s descendent territories,
                  if any, in the territory model hierarchy. A local rule is created within a single
                  territory and affects that territory only.</p>
              </td>

            </tr>

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

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

              <td class="entry" headers="d895357e564" data-title="Description">Required. The name of a rule associated with the territory. It isn’t necessary
                to fully qualify <span class="keyword parmname">ruleName</span> because Metadata API assumes that the
                rule belongs to the same model as the territory.</td>

            </tr>

          </tbody>

        </table>

## Declarative Metadata Sample Definition

The following example shows the definition of a Territory2 component.

<?xml version="1.0" encoding="UTF-8"?>
<Territory2 xmlns="http://soap.sforce.com/2006/04/metadata" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <name\>USA</name\>
    <description\>United States sales</description\>
    <accountAccessLevel\>Edit</accountAccessLevel\>
    <opportunityAccessLevel\>Read</opportunityAccessLevel\>
    <caseAccessLevel\>Edit</caseAccessLevel\>
    <contactAccessLevel\>Edit</contactAccessLevel\>
    <parentTerritory\>Worldwide\_Sales</parentTerritory\>
    <territory2Type\>Geo</territory2Type\>
    <objectAccessLevels\>
        <accessLevel\>All</accessLevel\>
        <objectType\>Lead</objectType\>
    </objectAccessLevels\>
    <ruleAssociations\>
        <ruleName\>AccRule1</name\>
        <inherited\>True</inherited\>
     </ruleAssociations\>
     <ruleAssociations\>
        <ruleName\>AccRule2</name\>
        <inherited\>False</inherited\>
     </ruleAssociations\>
     <customFields\>
        <name\>Activation\_DateTime\_\_c</name\>
        <value xsi:type="xsd:dateTime">2014-07-16T05:05:00.000Z</value\>
     </customFields\>
     <customFields\>
        <name\>AutoNumber\_\_c</name\>
        <value xsi:type="xsd:string">T# 000001</value\>
     </customFields\>
     <customFields\>
        <name\>DeactivationDate\_\_c</name\>
        <value xsi:type="xsd:date">2016-07-12</value\>
     </customFields\>
     <customFields\>
        <name\>External\_Id\_\_c</name\>
        <value xsi:type="xsd:string">AB2345</value\>
     </customFields\>
     <customFields\>
        <name\>ManagersPhone\_\_c</name\>
        <value xsi:nil="true"/>
     </customFields\>
</Territory2\>

The following is a package.xml sample. FY13 and FY14 represent the 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 organization.

<?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.USA</members\>
        <members\>FY13.Worldwide\_Sales</members\>
        <members\>FY14.APAC</members\>
        <members\>FY14.USA</members\>
        <name\>Territory2</name\>
    </types\>
        
    <version\>68.0</version\>
</Package\>

## Usage

- Triggers defined on Territory2 do _not_ fire during a deploy() operation unless there is a deployment failure. For example, when a child territory references a parent and deploys before the parent territory, the failed components try to deploy again one at a time, allowing triggers to run.
- Sales Territories 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.").
- For unlocked packaging, Territory2 requires packages without a namespace.

## 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.264.0.api_meta.meta/api_meta/file_based_zip_file.htm).