# Worked deliverables — ERD, data dictionary, sharing matrix

Fill these in; do not hand back the empty template. Example domain: warranty claims on machines sold through dealers.

## 1. ERD (Mermaid — lives in the repo, renders in most Git hosts)

```mermaid
erDiagram
    Account      ||--o{ Asset            : "owns (lookup)"
    Account      ||--o{ Warranty_Claim__c : "claimant (lookup)"
    Asset        ||--o{ Warranty_Claim__c : "covers (lookup)"
    Warranty_Claim__c ||--|{ Claim_Line__c : "master-detail"
    Product2     ||--o{ Claim_Line__c      : "part (lookup)"
    Warranty_Claim__c }o--|| Contract      : "under (lookup)"
```

Read it with the decisions attached:

- `Claim_Line__c` is **master-detail** to the claim: a line has no meaning without its claim, the claim's sharing should govern it, and the claim needs `Approved_Amount__c` as a roll-up summary.
- `Warranty_Claim__c` → `Asset` and → `Account` are **lookups**: assets and accounts outlive claims, and dealer access to a claim must not follow the account's sharing.
- No junction object: a claim covers exactly one asset. If a claim could cover several, `Claim_Asset__c` with master-detail to the claim (primary) and a lookup to Asset.
- Standard objects used where they fit: `Asset`, `Product2`, `Contract`, `Account`. `Case` was rejected as the claim object because claims need their own lifecycle, roll-ups and dealer sharing, and Case's support automation would fire on them.

## 2. Data dictionary (one row per field that matters)

| Object | API name | Label | Type | Req | Unique / External Id | Indexed | Values / target | Populated by | Sensitivity · compliance | Description |
|---|---|---|---|---|---|---|---|---|---|---|
| Warranty_Claim__c | `Claim_Number__c` | Claim Number | Auto Number | y | — | yes (auto) | `WC-{00000}` | platform | Internal · — | Human reference on dealer correspondence |
| Warranty_Claim__c | `ERP_Claim_Id__c` | ERP Claim Id | Text(32) | n | **External Id, unique** | yes | — | ERP integration | Internal · — | Upsert key from the ERP; never blank after sync |
| Warranty_Claim__c | `Status__c` | Status | Picklist (restricted) | y | — | no | Draft; Submitted; In Review; Approved; Rejected | user + flow | Internal · — | Owned by `Warranty_Claim_Before_Upsert` |
| Warranty_Claim__c | `Claimant_Contact__c` | Claimant | Lookup(Contact) | y | — | yes | Contact | user | Confidential · PII | Named person on the claim |
| Warranty_Claim__c | `Approved_Amount__c` | Approved Amount | Roll-Up Summary (SUM Claim_Line__c.Approved__c) | n | — | no | — | platform | Internal · — | Read-only; do not write from automation |
| Claim_Line__c | `Part__c` | Part | Lookup(Product2) | y | — | yes | Product2 | user | Internal · — | — |
| Claim_Line__c | `Failure_Notes__c` | Failure Notes | Long Text(4000) | n | — | no | — | user | Confidential · PII | Free text — never filter or report on it |

Sensitivity and compliance columns come from the field's **Data Sensitivity Level** (`securityClassification`) and **Compliance Categorization** (`complianceGroup`); keep them in sync by auditing with:

```sql
SELECT QualifiedApiName, SecurityClassification, ComplianceGroup, BusinessStatus, BusinessOwnerId
FROM FieldDefinition
WHERE EntityDefinition.QualifiedApiName = 'Warranty_Claim__c'
```

## 3. Sharing matrix

| Object | OWD internal | OWD external | Hierarchy | Sharing rules | Apex sharing | External users | Owner of the rule |
|---|---|---|---|---|---|---|---|
| `Warranty_Claim__c` | Private | Private | on | Criteria `Region__c = 'EMEA'` → EMEA Warranty (Read/Write) | `Warranty_Claim__Share` RowCause `Dealer_Access__c` granted to the dealer's partner user, rebuilt by `ClaimShareRecalcBatch` | Partner Community (roles + sharing rules) | Warranty Ops |
| `Claim_Line__c` | Controlled by Parent | Controlled by Parent | n/a | inherits | inherits | inherits | — |
| `Asset` | Private | Private | on | Owner-based Service → Warranty (Read Only) | — | Customer Community via Sharing Set on Account | Service Ops |

Licence decision recorded with it: dealers use **Partner Community** because they need roles and sharing rules over claims they did not create; end customers would only ever see their own assets and can stay on Customer Community with a Sharing Set.

## 4. Volume and rollout notes

```
Volume:   ~400 000 claims/year, 6 lines each → 2.8 M rows/year on Claim_Line__c
Indexes:  ERP_Claim_Id__c (auto, external Id); request a custom index on Status__c + CreatedDate
Skew:     ERP integration user owns claims → spread across 5 integration users, kept out of the role hierarchy
Loads:    Bulk API 2.0, parents (claims) before lines, sorted by claim, automation bypassed via
          Ignore_Validation_Rules__c on the load user during the migration window
Archive:  claims closed > 3 years → Warranty_Claim_History__b, index (Account__c, Closed_Date__c, Claim_Number__c);
          moved by Batch Apex, read back by Batch Apex or Bulk API 2.0 query — not Async SOQL
Repair:   roll-up recalculation and ClaimShareRecalcBatch after every bulk load
```
