sfdx-isv / territory-management-toolkit

The Territory Management Toolkit (TM-Tools) is a Salesforce CLI Plugin that provides tools for simplifying the migration of a Salesforce org from Territory Management (TM1) to Enterprise Territory Management (TM2).
BSD 3-Clause "New" or "Revised" License
9 stars 0 forks source link

Transform / Prepare sharing rules for re-insertion after TM1 to TM2 switch #3

Closed VivekMChawla closed 5 years ago

VivekMChawla commented 5 years ago

There are a number of Sharing Rules on Account (Criteria, Owner, and Territory) that may need some sort of transformation.

Here's what some of this metadata looks like in TM1 (Account.sharingRules):

<?xml version="1.0" encoding="UTF-8"?>
<SharingRules xmlns="http://soap.sforce.com/2006/04/metadata">
    <sharingOwnerRules>
        <fullName>MM</fullName>
        <accessLevel>Edit</accessLevel>
        <accountSettings>
            <caseAccessLevel>None</caseAccessLevel>
            <contactAccessLevel>Edit</contactAccessLevel>
            <opportunityAccessLevel>None</opportunityAccessLevel>
        </accountSettings>
        <label>MM</label>
        <sharedTo>
            <territory>MMC01NEast</territory>
        </sharedTo>
        <sharedFrom>
            <territoryAndSubordinates>District1100</territoryAndSubordinates>
        </sharedFrom>
    </sharingOwnerRules>
    <sharingTerritoryRules>
        <fullName>MSL_Accounts</fullName>
        <accessLevel>Edit</accessLevel>
        <accountSettings>
            <caseAccessLevel>None</caseAccessLevel>
            <contactAccessLevel>Edit</contactAccessLevel>
            <opportunityAccessLevel>None</opportunityAccessLevel>
        </accountSettings>
        <label>MSL Accounts</label>
        <sharedTo>
            <territoryAndSubordinates>MSL</territoryAndSubordinates>
        </sharedTo>
        <sharedFrom>
            <territoryAndSubordinates>x1101</territoryAndSubordinates>
        </sharedFrom>
    </sharingTerritoryRules>
    <sharingTerritoryRules>
        <fullName>MSL_Accounts2</fullName>
        <accessLevel>Edit</accessLevel>
        <accountSettings>
            <caseAccessLevel>None</caseAccessLevel>
            <contactAccessLevel>Edit</contactAccessLevel>
            <opportunityAccessLevel>None</opportunityAccessLevel>
        </accountSettings>
        <label>MSL Accounts2</label>
        <sharedTo>
            <territoryAndSubordinates>MSL</territoryAndSubordinates>
        </sharedTo>
        <sharedFrom>
            <territoryAndSubordinates>x1105</territoryAndSubordinates>
        </sharedFrom>
    </sharingTerritoryRules>
    <sharingTerritoryRules>
        <fullName>RAM_Rule</fullName>
        <accessLevel>Edit</accessLevel>
        <accountSettings>
            <caseAccessLevel>None</caseAccessLevel>
            <contactAccessLevel>Edit</contactAccessLevel>
            <opportunityAccessLevel>None</opportunityAccessLevel>
        </accountSettings>
        <label>RAM Rule</label>
        <sharedTo>
            <roleAndSubordinatesInternal>RegionalAccountsExecutive</roleAndSubordinatesInternal>
        </sharedTo>
        <sharedFrom>
            <territoryAndSubordinates>District1100</territoryAndSubordinates>
        </sharedFrom>
    </sharingTerritoryRules>
</SharingRules>

We need to know how this would look like in TM2 to determine the correct transformation logic

VivekMChawla commented 5 years ago

According to the TM1 to TM2 Migration Guide in Quip, the sharing rules should be updated such that every instance where a Territory Name is used, it is prepended by the model name, eg. ModelName.Territory_Name

Also, TM2 does not use "Account Territory" sharing rules (ie. the sharingTerritoryRules keys from the earlier TM1 sharing rules metadata example. These should be removed from any updated metadata.

Using the example from above, the territory values should be updated like this:

<?xml version="1.0" encoding="UTF-8"?>
<SharingRules xmlns="http://soap.sforce.com/2006/04/metadata">
    <sharingOwnerRules>
        <fullName>MM</fullName>
        <accessLevel>Edit</accessLevel>
        <accountSettings>
            <caseAccessLevel>None</caseAccessLevel>
            <contactAccessLevel>Edit</contactAccessLevel>
            <opportunityAccessLevel>None</opportunityAccessLevel>
        </accountSettings>
        <label>MM</label>
        <sharedTo>
            <territory>Imported_Territory.MMC01NEast</territory>
        </sharedTo>
        <sharedFrom>
            <territoryAndSubordinates>Imported_Territory.District1100</territoryAndSubordinates>
        </sharedFrom>
    </sharingOwnerRules>
</SharingRules>

I don't think we need to delete the "Account Territory" rules from the org. Those may disappear once the switch from TM1 to TM2 is flipped, but we should confirm with the product team.

The Original Territory Management (TM1) to Enterprise Territory Management (ETM/TM2) Migration FAQ document states the following:

Export any sharing rules involving territories (if any), and then delete these sharing rules involving territories.

Delete all the sharing rules where Group Type is "Territory" OR "TerritoryAndSubordinates" in GroupId and UserOrGroupId fields on Sharing object

IMPORTANT: Please make sure that you delete any sharing rules involving territory groups before TM1 is disabled.

This means we should add a feature to create a "destructive changes" deployment for the old rules.

VivekMChawla commented 5 years ago

This feature has been delivered as part of the 1.0.0 release.