# How do sharing rules and role hierarchies protect sensitive customer and deal data in Sales Cloud?

**Topic:** Sales Cloud · **Difficulty:** Medium · **Tags:** Sales Cloud, Security Model, Sharing Settings

Read it on the site: https://www.forcechallenges.com/interview-questions/how-do-sharing-rules-and-role-hierarchies-protect-sensitive-customer-and-deal-data-in-sales-cloud

## Answer

**Basics:** Two separate questions are answered: what can a user do with an object and field (profiles, permission sets, field-level security), and which individual records can they see (OWD, hierarchy, sharing). Sales usually sets Account, Contact and Opportunity OWD to Private so reps see only what they own.

**How it works:**
1. OWD is the most restrictive baseline (Private, Public Read Only, Public Read/Write, Controlled by Parent; Lead and Case add Public Read/Write/Transfer).
2. Role hierarchy gives managers access to subordinates' records (Grant Access Using Hierarchies).
3. Sharing rules (owner-based or criteria-based) extend Read or Read/Write to roles, groups or territories.
4. Account Teams, Opportunity Teams and manual sharing grant record-by-record access.
5. Apex managed sharing writes __Share rows with a custom RowCause for logic rules cannot express.
6. Implicit sharing gives parent/child visibility, for example access to an Opportunity grants read on its Account.

**Advanced / deep dive:** Sharing never restricts below OWD; to hide records you need a stricter OWD or restriction rules. Restriction Rules and Scoping Rules (newer features) can limit what users see even when sharing would allow it. View All and Modify All object permissions and View All/Modify All Data bypass sharing and are common leaks. Sharing recalculation is costly on large orgs; use Defer Sharing Calculations for big role or rule changes. Limits to remember: up to 300 sharing rules per object, with criteria-based rules limited to 50 per object; check current docs. Guest users have tighter sharing defaults. Layer Shield Platform Encryption for data at rest for highly sensitive fields.

**Code / config example:**
```apex
// Grant read access to an Account via Apex managed sharing
AccountShare s = new AccountShare(
  AccountId = acctId, UserOrGroupId = userId,
  AccountAccessLevel = 'Read', OpportunityAccessLevel = 'None',
  RowCause = 'Manual');
insert s;
```

**Hidden gotchas & must-remember points:**
- Sharing rules only grant access; they cannot take access away.
- For custom objects you can untick hierarchy access; for standard objects it is always on.
- Profile permissions such as View All Data override every sharing rule.
- Opportunity access can implicitly expose the parent Account in read-only fashion.
- Changes to OWD or rules trigger recalculation and can lock rule edits briefly.
- Apex sharing rows with RowCause Manual are removed when ownership changes; use a custom Apex sharing reason to persist.

**Best practice:** Start with the tightest OWD the business accepts, open access with roles and sharing rules, and audit View All and Modify All grants quarterly.

---
Source: ForceChallenges · last updated 2026-11-02
