---
schema_version: "1"
id: 5f1542d7251b1e488647bb12d3e2ed01e91701c1854b73d89953d5f454cf98d2
title: Row-Level Security Example based on Territory Hierarchy and Record Ownership
collection: admin
version: current
locale: en-us
portal_url: https://docs.salesforce.com/admin/current/en-us/analytics/264-0-0/bi_security_rowlevel_example_territoryhierarchy.md
canonical_url: https://help.salesforce.com/s/articleView?id=analytics.bi_security_rowlevel_example_territoryhierarchy.htm&release=264.0.0&type=5
source_site: help.salesforce.com
content_type: documentation
content_hash: d93179305abfb474cd7b8941aede0a3a095e67b8b695639f60a0c639276859ce
description: If your territory hierarchy is specified with Territory Hierarchy 2.0, you can create a dataset to implement row-level security based on the territory hierarchy and record ownership. This example shows how you do this with a dataset for opportunities.
products:
  - CRM Analytics
  - Cross Cloud
release: "264"
---
# Row-Level Security Example based on Territory Hierarchy and Record Ownership

If your territory hierarchy is specified with Territory Hierarchy 2.0, you can create a dataset to implement row-level security based on the territory hierarchy and record ownership. This example shows how you do this with a dataset for opportunities.

## Prerequisites

Territory Hierarchy in security predicate is a beta service that is subject to the Beta Services Terms at [Agreements - Salesforce.com](https://www.salesforce.com/company/legal/agreements/) and applicable terms in the [Product Terms Directory](https://ptd.salesforce.com/?_ga=2.247987783.1372150065.1709219475-629000709.1639001992). To use this feature, contact your Salesforce.com account rep or Customer Support via [help.salesforce.com](http://help.salesforce.com/?language=en_US). Use of this beta service is at the Customer's sole discretion.

## Source data

This example assumes you have this source data:

Users—here you have 5 users:

![Example user data](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-analytics-bi-264-0-0-production-enus/ec791473-f5b4-4f64-a656-9104f455d966/bi/images/bi/bi_security_rowlevel_example_territoryhierarchy_user.png)

Territory hierarchy—here the territories of California and Oregon are grouped under US West, which is included in the US territory:

![Example user data](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-analytics-bi-264-0-0-production-enus/ec791473-f5b4-4f64-a656-9104f455d966/bi/images/bi/bi_security_rowlevel_example_territoryhierarchy_territory2.png)

Territory hierarchy user associations–here users are associated with a territory. For example, John is associated with the territory of California.

![Example user data](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-analytics-bi-264-0-0-production-enus/ec791473-f5b4-4f64-a656-9104f455d966/bi/images/bi/bi_security_rowlevel_example_territoryhierarchy_userterritory2association.png)

Opportunities–here opportunities are identified by the territory in which they originated. For example, opportunity 1 is from California:

![Example user data](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-analytics-bi-264-0-0-production-enus/ec791473-f5b4-4f64-a656-9104f455d966/bi/images/bi/bi_security_rowlevel_example_territoryhierarchy_opportunity.png)

## Dataset content

Create a recipe or dataflow where you use the Flatten node to flatten the territory hierarchy into Territory2Ids,

![Example user data](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-analytics-bi-264-0-0-production-enus/ec791473-f5b4-4f64-a656-9104f455d966/bi/images/bi/bi_security_rowlevel_example_territoryhierarchy_territory2withterritoryhierarchy.png)

Then join the flattened territory hierarchy to the opportunity data:

![Example user data](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-analytics-bi-264-0-0-production-enus/ec791473-f5b4-4f64-a656-9104f455d966/bi/images/bi/bi_security_rowlevel_example_territoryhierarchy_opportunitywithterritoryid.png)

## Security predicate

Now add this Security Predicate to the Output node:

`'Territory2.TerritoryIDs' in ["$UserTerritory2Ids"]:`