Salesforce territory management test data has to do three things a generic account list never does: build the Territory2 hierarchy in the right order, populate assignment rules that match production logic, and give UserTerritory2Association records a reason to exist before any opportunity gets split by territory. Get the sequencing wrong and you end up with orphaned territory nodes, users assigned to models that never activated, and reports that show zero coverage. Bulk API v2 handles the volume fine. The problem is almost never throughput. It's dependency order and rule fidelity.
Most teams testing territory-based access or forecast rollups start by cloning a handful of Account records and manually tagging them. That approach breaks the moment a sandbox refresh wipes the manual tags, and it never exercises the actual assignment rule engine that production relies on to re-route accounts when ownership changes. If your test data doesn't exercise ObjectTerritory2AssociationRule the same way live data does, you're testing a fiction, not your org.
Why Flat Account Lists Don't Test Territory Assignment
Territory Management 2.0 is a layered model. A Territory2Model sits at the top, Territory2Type and Territory2 define the hierarchy underneath it, and UserTerritory2Association plus ObjectTerritory2Association connect users and accounts into that structure. A flat list of accounts with a Territory2Id field populated by hand skips every layer that actually matters for testing.
Here's what that shortcut misses. It misses rule evaluation order, since ObjectTerritory2AssociationRule records fire based on criteria and priority, not on whatever value you typed into a spreadsheet. It misses model state, because inactive Territory2Model records silently block all assignment, and a hand-built test record won't tell you that. It misses the forecast and opportunity split behavior that only kicks in once an account sits inside an active, correctly ruled territory.
Once you accept that the hierarchy itself is the thing under test, the generation problem changes shape. You're no longer inserting accounts with a territory label attached. You're building a tree, then wiring accounts and users into that tree in an order the Salesforce metadata actually enforces.
The Five Objects That Make Up a Territory Model
Before any load runs, map out which objects your test needs and in what order they depend on each other. CloudEzee's schema reader pulls this directly from the org's territory metadata so you aren't guessing at field names or picklist values by hand.
| Object | Role | Depends On |
|---|---|---|
| Territory2Model | Top-level container, must be in Planning or Active state | None |
| Territory2Type | Classifies territories (e.g. Geography, Named Account) | Territory2Model |
| Territory2 | Individual node in the hierarchy, supports parent/child nesting | Territory2Model, Territory2Type |
| UserTerritory2Association | Assigns a user to a territory with a role | Territory2, User |
| ObjectTerritory2AssociationRule | Defines the criteria that route accounts into territories | Territory2 |
Notice that ObjectTerritory2Association, the junction that actually links an Account to a Territory2, is populated by running the assignment rules rather than inserted directly in most production orgs. Test data generation needs to respect that same path, or your coverage tells you nothing about whether the rules themselves work.
Sequencing Bulk API v2 Loads Across Hierarchy Levels
Bulk API v2 doesn't care about object relationships. It inserts what you send it. The sequencing discipline has to come from whatever is driving the load, and that's where most manual scripts fall apart under volume.
A working load order looks like this: Territory2Model first, left in Planning state so child territories can be added without triggering premature assignment runs. Territory2Type records next, since Territory2 won't accept a type reference that doesn't exist yet. Then Territory2 itself, inserted level by level from the root down, because a child territory needs its parent's resolved Salesforce ID before it can reference it.
After the hierarchy is built, UserTerritory2Association records go in, tying test users to specific nodes with roles like Territory Manager or Sales Rep. Only after the model is activated should ObjectTerritory2AssociationRule records run, because rule evaluation against accounts assumes an active, stable hierarchy underneath it. Activating the model too early, before the full tree is loaded, causes partial rule runs that leave some accounts unassigned, which is exactly the kind of inconsistency that makes a QA report unreliable.
This is where generating realistic chunk sizes matters too. A territory hierarchy five levels deep with branching nodes at each level produces more parent-child batch dependencies than a typical junction object load, so chunking by hierarchy depth rather than flat record count keeps the Bulk API v2 job from racing ahead of itself.
Simulating Rule-Based Assignment Without Running the Real Engine
Running the live assignment rule engine against thousands of test accounts in a sandbox is slow, and in some orgs it's disabled outside production entirely. That leaves two honest options for test data generation, and most teams default to the wrong one.
Option one is inserting ObjectTerritory2Association records directly, bypassing the rule engine and just stating which account belongs to which territory. This is fast but fake. It tests whatever downstream logic depends on an account having a territory, but it never validates that your rules are correct, and a rule change in production won't surface as a test failure.
Option two is generating accounts whose field values are deliberately shaped to match real assignment criteria, then letting the actual rule engine assign them. If your rules route accounts by BillingState and Industry, your test data generator needs to produce accounts with the right combinations of those fields, not random values. This is more work upfront but it's the only approach that actually tests the rules rather than assuming them. SproutEzee's schema read picks up the criteria fields referenced in ObjectTerritory2AssociationRule and biases generated account values toward them, so a meaningful share of test accounts actually get routed by the rules instead of falling through to a default bucket.
Testing Opportunity Splits and Forecast Rollups by Territory
Territory assignment rarely exists for its own sake. Most orgs that implement Territory2 wire it into opportunity splits, forecast categories, and sharing visibility, and that's where test data gaps show up as real bugs rather than abstract data quality issues.
An Opportunity tied to an account in an active territory inherits territory-based sharing automatically, but OpportunitySplit records tied to territory roles need to be generated separately, matched against the UserTerritory2Association roles you set up earlier. If your test users don't have roles that match what the split logic expects, forecast rollups silently show zero for that territory, and it looks like a flow bug when it's actually a data generation gap.
Worth testing deliberately: an account that moves between territories mid-quarter. Reassigning an account after opportunities already exist tests whether your org's forecast history preserves prior splits or recalculates them, and that behavior varies a lot between orgs depending on custom automation. Test data that never moves accounts between territories will never surface that edge case, and in my experience it's one of the most common sources of forecast discrepancy tickets after a territory reorg.
A Field Checklist for Territory2 Test Records
Four fields consistently get overlooked when teams hand-build Territory2 test records, and all four cause silent failures downstream rather than loud errors.
ParentTerritory2Id needs to resolve to an already-inserted parent, not a placeholder value, or the hierarchy flattens and rollup reports misrepresent coverage. Territory2ModelId must point to a model in an appropriate state for the test phase, Planning while building, Active once assignment should run. AccountAccessLevel and OpportunityAccessLevel on the territory itself determine what sharing actually gets granted, and defaulting both to Edit regardless of the org's real configuration will mask sharing bugs that only show up with Read-only access in production.
Territory2 also carries a Description field that rarely matters functionally but is worth populating with something traceable, like a batch ID or generation timestamp, so QA can tell real territories apart from test ones during a shared sandbox refresh. It's a small thing, but it saves real time during cleanup.
Frequently Asked Questions
Can I insert ObjectTerritory2Association records directly instead of running assignment rules?
Yes, and it's faster, but it only tests whatever depends on an account having a territory assigned. It does not validate that your ObjectTerritory2AssociationRule criteria actually route accounts correctly, so a rule misconfiguration in production would not show up as a test failure. Direct inserts are fine for downstream testing like sharing or forecast rollups, but they should not replace rule-based testing entirely.
What state should Territory2Model be in while loading test data?
Keep it in Planning state while the hierarchy and user associations are being built, then move it to Active only once everything underneath is complete. Activating too early can trigger partial assignment rule runs against an incomplete hierarchy, which leaves some accounts unassigned and produces inconsistent coverage reports.
Why do forecast rollups show zero for a territory even though accounts are assigned correctly?
This usually traces back to OpportunitySplit records that don't match the roles defined in UserTerritory2Association for that territory. If test users have roles the split logic doesn't expect, the rollup has nothing valid to sum. Generating split records with roles aligned to the actual territory assignments fixes this.
How does Bulk API v2 handle the parent-child dependencies in a Territory2 hierarchy?
Bulk API v2 itself has no awareness of object relationships, so it will insert records in whatever order they're submitted regardless of hierarchy validity. The load process needs to sequence Territory2 records level by level, resolving each parent's ID before submitting its children, or the hierarchy will come out flattened or partially broken.
Should test data include accounts that move between territories?
Yes, because territory reassignment mid-quarter is a common real-world event and it exercises forecast history and split recalculation logic that static assignments never touch. Many orgs behave differently depending on custom automation tied to territory changes, so this scenario often surfaces bugs that standard coverage misses entirely.