Loading...
Loading...
Use this skill to create and activate a Territory Type, Territory Model, and Territories for Life Sciences Cloud. Trigger when the user says 'set up territories', 'create territory model', 'configure territory hierarchy for Life Sciences', 'territory setup for LSC', or 'create territories for Life Sciences Cloud'. Creates a Geographical territory type, an LSC Territory Model, and a 3-level territory hierarchy (Region, District, Territory). Confirms names with the user, shows a preview, then deploys and activates the model. DO NOT TRIGGER when: user wants to validate prerequisites, assign users to territories, create territory assignment rules, or run the full end-to-end Life Sciences Cloud setup / orchestration (that is the `life-sciences-fieldsalesrep-coordinate` orchestrator's job — this skill runs only as a standalone territory setup).
npx skill4agent add forcedotcom/sf-skills life-sciences-territory-configuresflife-sciences-prerequisites-validatelife-sciences-fieldsalesrep-coordinatesf config get target-orgreferences/territory-metadata.md| Component | Default Name |
|-----------|-------------|
| Territory Type | Geographical |
| Territory Model | LSC Territory Model |
| Territory (Level 1 - Region) | RD - West 20D |
| Territory (Level 2 - District) | DM - San Francisco 20D02 |
| Territory (Level 3 - Territory) | TM - SPC - San Francisco North 20D02T11 |references/territory-metadata.md=== Territory Type ===
Name: <confirmed name>
Priority: 1
=== Territory Model ===
Name: <confirmed model name>
=== Territory Hierarchy ===
Level 1 (Region): <confirmed region name>
└── Level 2 (District): <confirmed district name>
└── Level 3 (Territory): <confirmed territory name>
Access Levels (all territories):
- Account: Read
- Contact: Edit
- Case: None
- Opportunity: Nonereferences/territory-metadata.mdterritory-deploy/
├── sfdx-project.json
└── force-app/
└── main/
└── default/
└── territory2Models/
├── <ModelApiName>.territory2Model-meta.xml
└── <ModelApiName>/
├── territory2Types/
│ └── <TypeApiName>.territory2Type-meta.xml
└── territories/
├── <Level1ApiName>.territory2-meta.xml
├── <Level2ApiName>.territory2-meta.xml
└── <Level3ApiName>.territory2-meta.xmlreferences/territory-metadata.mdsf project deploy start --source-dir territory-deploy/force-app --target-org <org>STOP-GATE (component count). The single deploy package must land the complete hierarchy: 1 Territory2Type + 1 Territory2Model + 3 Territory2 records (one Region, one District, one Territory). Confirm the deploy result reports 0 component failures AND verify the territories exist before activating:bashsf data query --query "SELECT COUNT(Id) c FROM Territory2 WHERE Territory2Model.DeveloperName = '<ModelApiName>'" --target-org <org> --jsonThe count MUST be 3. A parent-reference failure (e.g. the District deploying before its Region) can land a partial hierarchy — a Level-3 territory with no path to its Region silently breaks downstream user/visit territory assignment. Do NOT activate the model (Phase 4) until all 3 territories are present with 0 deploy failures.
Note: Once a Territory Model is activated, it can be deactivated but cannot be deleted. Do you want to proceed with activation?
'Activating''Active'# Query the model ID and current state
sf data query --query "SELECT Id, State FROM Territory2Model WHERE DeveloperName = '<ModelApiName>' LIMIT 1" --target-org <org> --jsonPlanningsf data update record --sobject Territory2Model --record-id <ModelId> --values "State='Activating'" --target-org <org>references/territory-metadata.mdActivatingActivesf data query --query "SELECT Id, DeveloperName, State FROM Territory2Model WHERE DeveloperName='<ModelApiName>'" --target-org <org>ActivatingActivePlanningActivatingActive| Constraint | Rationale |
|---|---|
| Create exactly one territory per level — one Level-1 Region, one Level-2 District, one Level-3 Territory (3 territories total) | Skill produces a single representative hierarchy branch, not a fully populated multi-child tree |
| Always confirm names before creating | User may want to customize territory names for their org |
| Show preview before deploying | User should see exactly what will be created |
| Deploy all components together | Territory hierarchy has dependencies (parent references) |
| Warn user before activation that model cannot be deleted once active | Irreversible action — user must explicitly consent |
Set State to | The platform handles the async transition from Activating → Active |
Target the update by | Both forms work for |
| Clean up temp directory after deploy | Don't leave deployment artifacts behind |
| Issue | Resolution |
|---|---|
| Territory model already exists with same name | Check first with a query; ask user if they want a different name |
| Territory type already exists | Check first; reuse existing type if it matches |
| Deploy fails due to parent territory not found | Ensure all territories are in the same deployment package |
Setting State to | Always set State to |
Model state shows | This is normal — activation is async. Wait and re-query until |
| API name conflicts | Ensure generated API names don't conflict with existing metadata |
| File | When to read |
|---|---|
| During all phases — contains XML templates, file structure, and default values for territory components |