Sharing Rules Generator
Get, create, edit, and delete Salesforce Sharing Rules metadata to control record-level access beyond org-wide defaults. Supports criteria-based rules, role/group-based owner rules, and guest user rules for Experience Sites.
Scope
- In scope: Creating, editing, deleting, and retrieving (getting)
sharingCriteriaRules, sharingOwnerRules, and sharingGuestRules metadata; retrieving existing sharing rules from an org using the Metadata API Retrieve pattern; appending new rules to existing files; modifying rule criteria or access levels; removing rules from metadata files; configuring rules for Guest and Portal profiles.
- Out of scope: Changing org-wide defaults (OWD/sharing model), creating Experience Sites, configuring permission sets or profiles (use
platform-permission-set-generate), territory-based sharing rules.
Clarifying Questions
Before proceeding, confirm with the user if not already clear:
For Get operations:
- Which object's sharing rules should be retrieved? (standard or custom object API name, or all objects)
- Which target org should the rules be retrieved from? (org alias or default)
For Create operations:
- Which object should the sharing rule apply to? (standard or custom object API name)
- What type of rule? (criteria-based, role/group-based owner rule, or guest user rule)
- Who should records be shared with? (role name, group, portal role, or guest user nickname)
- What access level? (Read or Read/Write)
- For criteria-based rules: what field conditions should match?
For Edit operations:
- Which existing rule should be modified? (rule fullName or label)
- What should change? (access level, criteria, label — note:
sharedTo and sharedFrom cannot be edited in place)
For Delete operations:
- Which rule(s) should be removed? (rule fullName or label)
- Confirm the object the rule belongs to
Required Inputs
Gather or infer before proceeding:
- Object API name: The sObject the rule targets (e.g.,
Account, Property__c)
- Rule type: One of
sharingCriteriaRules, sharingOwnerRules, or sharingGuestRules
- Shared-to target: Role, group, portal role, or guest user community nickname
- Access level:
Read or Edit (maps to Read-Only or Read/Write)
- Criteria (for criteria/guest rules): Field name, operation, and value for each filter item
Defaults unless specified:
- Access level:
Read
includeRecordsOwnedByAll: true for criteria rules
includeHVUOwnedRecords: false for guest rules
- Account sharing rules include
accountSettings with all sub-access levels set to None
Workflow
Steps are sequential within each phase. Phase 3 branches by operation type — execute only the matching branch. Phase 4 applies to create, edit, and delete only (get operations end at Phase 3).
Phase 1 — Discover
Resolve the SFDX project path — find the project's sfdx-project.json and identify the package directory for sharingRules/.
Always retrieve the latest sharing rules from the org using the Metadata API Retrieve pattern:
sf project retrieve start --metadata "SharingRules:<ObjectName>" --target-org <org>
This ensures the local file reflects the current org state. Never trust a local file that may be stale — edits or deletes against a stale file can recreate rules that were already removed in the org or overwrite changes made by other users.
Read the retrieved file — parse <packageDir>/sharingRules/<ObjectName>.sharingRules-meta.xml to understand existing rules and avoid duplicates.
Phase 2 — Determine Operation and Rule Type
Identify the operation — determine whether the user wants to get, create, edit, or delete a sharing rule.
Select the rule type based on user intent. Read references/rule-types.md for the complete schema of each type and its required elements.
For Account sharing rules: the accountSettings element is required. Default sub-access levels to None unless the user specifies otherwise.
For Guest rules: the sharedTo must use <guestUser> with the site guest user's community nickname. Never use <role> or <group> for guest rules.
Phase 3 — Execute Operation
For Get:
8a. Use the file already retrieved in Phase 1 — the retrieve in step 2 already pulled the latest <ObjectName>.sharingRules-meta.xml from the org. No additional retrieve is needed.
8b. Read and present the retrieved rules — parse the .sharingRules-meta.xml file and present the rules to the user in a readable format showing:
- Rule name (fullName) and label
- Rule type (criteria-based, owner-based, or guest)
- Access level
- Shared-to target
- Criteria (if applicable)
For get operations, skip Phase 4 (no write needed). The retrieve itself writes the metadata file to the local project.
For Create:
8a. Construct the XML following the schema in references/rule-types.md. Key structure:
- One .sharingRules-meta.xml file per object
- All rules for the same object go in the same file
- If appending to an existing file, add the new rule element inside the existing <SharingRules> root
8b. Name the rule — derive <fullName> from the intent (PascalCase, no spaces, descriptive). Generate a matching <label> in Title Case with spaces.
For Edit:
8a. Locate the target rule — find the rule by <fullName> or <label> in the existing .sharingRules-meta.xml file.
8b. Gate unsupported edits — the platform does NOT support in-place modification of <sharedTo> or <sharedFrom> elements. If the user requests a change to the sharing target or source, refuse the edit and instruct them to delete the existing rule and create a new one with the desired target. This is the same pattern used for rule-type changes (see TC-16).
8c. Determine modifications based on rule type:
- Owner-based rules (sharingOwnerRules): only <accessLevel> can be edited. The platform does not support modifying any other element (sharedTo, sharedFrom, label) on owner rules. If the user requests changes beyond access level, refuse and instruct them to delete + create.
- Criteria-based rules (sharingCriteriaRules): supported editable elements are <accessLevel>, <criteriaItems>, <label>, and <booleanFilter>.
- Guest rules (sharingGuestRules): supported editable elements are <accessLevel>, <criteriaItems>, <label>, and <includeHVUOwnedRecords>.
For Delete:
8a. Locate the target rule — find the rule by <fullName> or <label> in the existing .sharingRules-meta.xml file.
8b. Count remaining rules — run scripts/count-remaining-rules.sh <file> to get the total rule count. If the count is 1 (only the rule being deleted), the file must be removed entirely in Phase 4.
8c. Delegate destructive deployment to platform-destructive-deploy — a normal sf project deploy start is additive and will NOT remove a rule from the org. Delegate to the platform-destructive-deploy skill with the following context:
- Metadata type: SharingCriteriaRule, SharingOwnerRule, or SharingGuestRule (depending on the rule type)
- Member: <ObjectName>.<RuleFullName>
- Target org: the user's specified org
Phase 4 — Write and Verify
Apply the change:
- Create: Write the file to
<packageDir>/sharingRules/<ObjectName>.sharingRules-meta.xml.
- Edit: Update only the elements identified in step 8b; preserve all other elements exactly as they were.
- Delete (rules remain): Write the updated file with the target rule removed.
- Delete (last rule): Remove the file
<packageDir>/sharingRules/<ObjectName>.sharingRules-meta.xml entirely.
Run the verification checklist below and consult the examples files (examples/create-cases.md, examples/edit-cases.md, examples/delete-cases.md) for scenario-specific expected behaviors before presenting output.
Verification Checklist
Universal Checks
Criteria Rule Checks
Guest Rule Checks CRITICAL
Owner Rule Checks
Edit Operation Checks
Delete Operation Checks
Account-Specific Checks CRITICAL
Rules / Constraints
| Constraint |
Rationale |
One .sharingRules-meta.xml file per object |
Platform requirement — multiple files cause deployment errors |
Guest rules must use <guestUser> in sharedTo |
Using <role> or <group> causes: "Specify a guest user's nickname for the guestUser field" |
Account rules require <accountSettings> |
Without it: "AccountSettings is required for account sharing rules" |
includeRecordsOwnedByAll is required on criteria rules |
Missing it causes: "Required field is missing: sharingCriteriaRules" |
includeHVUOwnedRecords is required on guest rules |
Missing it causes deployment failure |
| Criteria field values must exist as picklist values on the org |
Invalid values cause: "Picklist value does not exist" |
Never hardcode file paths — resolve from sfdx-project.json |
Customer projects use custom package directories |
For managed package custom objects, use the full API name including namespace prefix (e.g., ns__Object__c) |
Namespace-prefixed objects store sharing rules under the prefixed name |
sharedTo and sharedFrom cannot be edited in place |
Platform does not support modifying sharing targets — deploy will fail. Delete the rule and create a new one instead |
Owner-based rules only support editing accessLevel |
No other field (label, sharedTo, sharedFrom) can be modified on owner rules — delete and recreate instead |
| Always retrieve from the org before edit or delete |
Local files may be stale; editing a stale file can recreate deleted rules or overwrite concurrent changes |
| Deleting a rule requires a destructive deployment |
A normal deploy is additive — it will not remove rules from the org. Delegate to platform-destructive-deploy |
| Edit must preserve unmodified elements |
Changing only accessLevel must not alter criteriaItems or other fields |
| Delete must remove the entire rule block |
Partial deletion leaves invalid XML and causes deployment failures |
| Delete last rule removes the file |
An empty <SharingRules> root with no children is invalid metadata |
Gotchas
| Issue |
Resolution |
Guest rule uses <role> instead of <guestUser> |
Replace with <guestUser>CommunityNickname</guestUser> |
Account rule missing accountSettings |
Add <accountSettings> with all three access level sub-elements set to None |
Criteria rule missing includeRecordsOwnedByAll |
Add <includeRecordsOwnedByAll>true</includeRecordsOwnedByAll> |
| Picklist value mismatch |
Query the org for valid values before generating criteria |
| Appending duplicates existing rule name |
Check existing <fullName> values before writing |
| Guest user nickname not found |
Query: SELECT CommunityNickname FROM User WHERE UserType='Guest' AND IsActive=true |
User requests edit to sharedTo or sharedFrom |
Not supported — refuse the edit and instruct user to delete + create a new rule |
User requests edit to owner rule beyond accessLevel |
Not supported — owner rules only allow accessLevel edits. Refuse and instruct user to delete + create |
| Editing changes rule type (e.g., criteria → owner) |
Not supported — delete the old rule and create a new one instead |
| Local file is stale (rule deleted/changed in org) |
Always retrieve fresh from org before edit or delete to avoid recreating removed rules |
| Delete deployed with normal deploy (no destructive manifest) |
Rule remains in the org — delegate to platform-destructive-deploy for proper removal |
| Deleting a rule referenced by other automation |
Warn the user about potential downstream impact |
| Delete leaves malformed XML |
Ensure proper XML structure after removal; validate the file is well-formed |
Output Expectations
Deliverables:
- For get operations:
<packageDir>/sharingRules/<ObjectName>.sharingRules-meta.xml — retrieved sharing rules file from the org, plus a formatted summary of all rules found
- For create/edit/delete operations:
<packageDir>/sharingRules/<ObjectName>.sharingRules-meta.xml — complete sharing rules file for the target object
Cross-Skill Integration
| Need |
Delegate to |
| Permission set configuration |
platform-permission-set-generate skill |
| Custom object creation (if target object doesn't exist) |
platform-custom-object-generate skill |
| Destructive deployment (rule deletion from org) |
platform-destructive-deploy skill |
Reference File Index
| File |
When to read |
references/rule-types.md |
Phase 2 — before generating any rule, to get the complete XML schema for each rule type |
scripts/count-remaining-rules.sh |
Phase 3, step 8b (Delete) — count sharing rule elements to determine if file should be removed |
examples/create-cases.md |
Phase 4, step 10 — expected behavior for create and append scenarios |
examples/edit-cases.md |
Phase 4, step 10 — expected behavior for edit scenarios |
examples/delete-cases.md |
Phase 4, step 10 — expected behavior for delete scenarios |
1---
2name: platform-sharing-rules-generate
3description: "Use this skill when users need to get, create, edit, delete, or manage Salesforce Sharing Rules metadata. TRIGGER when: users mention sharing rules, record sharing, criteria-based sharing, role-based sharing, guest user sharing, sharingRules, sharingCriteriaRules, sharingGuestRules, sharingOwnerRules, .sharingRules-meta.xml files, or ask to share records with specific roles or groups. Also trigger when users want to retrieve or view existing sharing rules from an org, modify or remove existing sharing rules, or update sharing rule criteria or access levels. DO NOT TRIGGER when user needs permission sets or profiles (use platform-permission-set-generate), or needs object-level security rather than record-level sharing (use platform-permission-set-generate)."
4metadata:
5 version: "1.3"
6 domains: ["Platform"]
7 minApiVersion: "60.0"
8 relatedSkills:
9 - "platform-custom-object-generate"
10 - "platform-permission-set-generate"
11 cliTools:
12 - tool: ["sf"]
13 semver: ">=2.0.0"
14---
15
16# Sharing Rules Generator
17
18Get, create, edit, and delete Salesforce Sharing Rules metadata to control record-level access beyond org-wide defaults. Supports criteria-based rules, role/group-based owner rules, and guest user rules for Experience Sites.
19
20## Scope
21
22- **In scope**: Creating, editing, deleting, and retrieving (getting) `sharingCriteriaRules`, `sharingOwnerRules`, and `sharingGuestRules` metadata; retrieving existing sharing rules from an org using the Metadata API Retrieve pattern; appending new rules to existing files; modifying rule criteria or access levels; removing rules from metadata files; configuring rules for Guest and Portal profiles.
23- **Out of scope**: Changing org-wide defaults (OWD/sharing model), creating Experience Sites, configuring permission sets or profiles (use `platform-permission-set-generate`), territory-based sharing rules.
24
25---
26
27## Clarifying Questions
28
29Before proceeding, confirm with the user if not already clear:
30
31### For Get operations:
32- Which object's sharing rules should be retrieved? (standard or custom object API name, or all objects)
33- Which target org should the rules be retrieved from? (org alias or default)
34
35### For Create operations:
36- Which object should the sharing rule apply to? (standard or custom object API name)
37- What type of rule? (criteria-based, role/group-based owner rule, or guest user rule)
38- Who should records be shared with? (role name, group, portal role, or guest user nickname)
39- What access level? (Read or Read/Write)
40- For criteria-based rules: what field conditions should match?
41
42### For Edit operations:
43- Which existing rule should be modified? (rule fullName or label)
44- What should change? (access level, criteria, label — note: `sharedTo` and `sharedFrom` cannot be edited in place)
45
46### For Delete operations:
47- Which rule(s) should be removed? (rule fullName or label)
48- Confirm the object the rule belongs to
49
50---
51
52## Required Inputs
53
54Gather or infer before proceeding:
55
56- **Object API name**: The sObject the rule targets (e.g., `Account`, `Property__c`)
57- **Rule type**: One of `sharingCriteriaRules`, `sharingOwnerRules`, or `sharingGuestRules`
58- **Shared-to target**: Role, group, portal role, or guest user community nickname
59- **Access level**: `Read` or `Edit` (maps to Read-Only or Read/Write)
60- **Criteria** (for criteria/guest rules): Field name, operation, and value for each filter item
61
62Defaults unless specified:
63- Access level: `Read`
64- `includeRecordsOwnedByAll`: `true` for criteria rules
65- `includeHVUOwnedRecords`: `false` for guest rules
66- Account sharing rules include `accountSettings` with all sub-access levels set to `None`
67
68---
69
70## Workflow
71
72Steps are sequential within each phase. Phase 3 branches by operation type — execute only the matching branch. Phase 4 applies to create, edit, and delete only (get operations end at Phase 3).
73
74### Phase 1 — Discover
75
761. **Resolve the SFDX project path** — find the project's `sfdx-project.json` and identify the package directory for `sharingRules/`.
77
782. **Always retrieve the latest sharing rules from the org** using the Metadata API Retrieve pattern:
79 ```bash
80 sf project retrieve start --metadata "SharingRules:<ObjectName>" --target-org <org>
81 ```
82 This ensures the local file reflects the current org state. Never trust a local file that may be stale — edits or deletes against a stale file can recreate rules that were already removed in the org or overwrite changes made by other users.
83
843. **Read the retrieved file** — parse `<packageDir>/sharingRules/<ObjectName>.sharingRules-meta.xml` to understand existing rules and avoid duplicates.
85
86### Phase 2 — Determine Operation and Rule Type
87
884. **Identify the operation** — determine whether the user wants to **get**, **create**, **edit**, or **delete** a sharing rule.
89
905. **Select the rule type** based on user intent. Read `references/rule-types.md` for the complete schema of each type and its required elements.
91
926. **For Account sharing rules**: the `accountSettings` element is required. Default sub-access levels to `None` unless the user specifies otherwise.
93
947. **For Guest rules**: the `sharedTo` must use `<guestUser>` with the site guest user's community nickname. Never use `<role>` or `<group>` for guest rules.
95
96### Phase 3 — Execute Operation
97
98#### For Get:
99
1008a. **Use the file already retrieved in Phase 1** — the retrieve in step 2 already pulled the latest `<ObjectName>.sharingRules-meta.xml` from the org. No additional retrieve is needed.
101
1028b. **Read and present the retrieved rules** — parse the `.sharingRules-meta.xml` file and present the rules to the user in a readable format showing:
103 - Rule name (`fullName`) and label
104 - Rule type (criteria-based, owner-based, or guest)
105 - Access level
106 - Shared-to target
107 - Criteria (if applicable)
108
109 For get operations, skip Phase 4 (no write needed). The retrieve itself writes the metadata file to the local project.
110
111#### For Create:
112
1138a. **Construct the XML** following the schema in `references/rule-types.md`. Key structure:
114 - One `.sharingRules-meta.xml` file per object
115 - All rules for the same object go in the same file
116 - If appending to an existing file, add the new rule element inside the existing `<SharingRules>` root
117
1188b. **Name the rule** — derive `<fullName>` from the intent (PascalCase, no spaces, descriptive). Generate a matching `<label>` in Title Case with spaces.
119
120#### For Edit:
121
1228a. **Locate the target rule** — find the rule by `<fullName>` or `<label>` in the existing `.sharingRules-meta.xml` file.
123
1248b. **Gate unsupported edits** — the platform does NOT support in-place modification of `<sharedTo>` or `<sharedFrom>` elements. If the user requests a change to the sharing target or source, refuse the edit and instruct them to delete the existing rule and create a new one with the desired target. This is the same pattern used for rule-type changes (see TC-16).
125
1268c. **Determine modifications based on rule type**:
127 - **Owner-based rules (`sharingOwnerRules`)**: only `<accessLevel>` can be edited. The platform does not support modifying any other element (`sharedTo`, `sharedFrom`, `label`) on owner rules. If the user requests changes beyond access level, refuse and instruct them to delete + create.
128 - **Criteria-based rules (`sharingCriteriaRules`)**: supported editable elements are `<accessLevel>`, `<criteriaItems>`, `<label>`, and `<booleanFilter>`.
129 - **Guest rules (`sharingGuestRules`)**: supported editable elements are `<accessLevel>`, `<criteriaItems>`, `<label>`, and `<includeHVUOwnedRecords>`.
130
131#### For Delete:
132
1338a. **Locate the target rule** — find the rule by `<fullName>` or `<label>` in the existing `.sharingRules-meta.xml` file.
134
1358b. **Count remaining rules** — run `scripts/count-remaining-rules.sh <file>` to get the total rule count. If the count is 1 (only the rule being deleted), the file must be removed entirely in Phase 4.
136
1378c. **Delegate destructive deployment to `platform-destructive-deploy`** — a normal `sf project deploy start` is additive and will NOT remove a rule from the org. Delegate to the `platform-destructive-deploy` skill with the following context:
138 - Metadata type: `SharingCriteriaRule`, `SharingOwnerRule`, or `SharingGuestRule` (depending on the rule type)
139 - Member: `<ObjectName>.<RuleFullName>`
140 - Target org: the user's specified org
141
142### Phase 4 — Write and Verify
143
1449. **Apply the change**:
145 - **Create**: Write the file to `<packageDir>/sharingRules/<ObjectName>.sharingRules-meta.xml`.
146 - **Edit**: Update only the elements identified in step 8b; preserve all other elements exactly as they were.
147 - **Delete (rules remain)**: Write the updated file with the target rule removed.
148 - **Delete (last rule)**: Remove the file `<packageDir>/sharingRules/<ObjectName>.sharingRules-meta.xml` entirely.
149
15010. **Run the verification checklist** below and consult the examples files (`examples/create-cases.md`, `examples/edit-cases.md`, `examples/delete-cases.md`) for scenario-specific expected behaviors before presenting output.
151
152---
153
154## Verification Checklist
155
156### Universal Checks
157- [ ] Does the file have the XML declaration and `<SharingRules xmlns="http://soap.sforce.com/2006/04/metadata">` root?
158- [ ] Is there exactly one file per object with all rules inside it?
159- [ ] Does `<fullName>` use PascalCase with no spaces?
160- [ ] Is `<label>` present and human-readable?
161- [ ] Is `<accessLevel>` one of `Read` or `Edit`?
162
163### Criteria Rule Checks
164- [ ] Is `<includeRecordsOwnedByAll>` present (required boolean)?
165- [ ] Does each `<criteriaItems>` have `<field>`, `<operation>`, and `<value>`?
166- [ ] Are picklist values valid for the target org?
167
168### Guest Rule Checks CRITICAL
169- [ ] Does `<sharedTo>` use `<guestUser>` (NOT `<role>` or `<group>`)?
170- [ ] Is `<includeHVUOwnedRecords>` present (required boolean)?
171- [ ] Is `<includeRecordsOwnedByAll>` ABSENT (only for criteria rules, not guest rules)?
172
173### Owner Rule Checks
174- [ ] Does the rule have both `<sharedFrom>` and `<sharedTo>` elements?
175- [ ] Do both use valid `<role>`, `<roleAndSubordinates>`, or `<group>` targets?
176
177### Edit Operation Checks
178- [ ] Was the edit against a freshly retrieved file (not a stale local copy)?
179- [ ] Is the edit limited to supported fields for the rule type?
180 - Owner rules: only `accessLevel`
181 - Criteria rules: `accessLevel`, `criteriaItems`, `label`, `booleanFilter`
182 - Guest rules: `accessLevel`, `criteriaItems`, `label`, `includeHVUOwnedRecords`
183- [ ] Was `sharedTo`/`sharedFrom` left unchanged? (if user requested that change, refuse and advise delete + create)
184- [ ] Was only the intended element modified?
185- [ ] Are all required elements still present after the edit?
186- [ ] Does the modified rule still pass the universal checks above?
187
188### Delete Operation Checks
189- [ ] Was the correct rule removed (matched by `<fullName>`)?
190- [ ] Is the remaining XML well-formed with proper `<SharingRules>` root?
191- [ ] If no rules remain, was the file removed entirely?
192- [ ] Was `platform-destructive-deploy` delegated to with the correct metadata type (`SharingCriteriaRule`, `SharingOwnerRule`, or `SharingGuestRule`)?
193
194### Account-Specific Checks CRITICAL
195- [ ] If object is Account, is `<accountSettings>` present with all three sub-elements?
196- [ ] Are `<caseAccessLevel>`, `<contactAccessLevel>`, `<opportunityAccessLevel>` all set?
197
198---
199
200## Rules / Constraints
201
202| Constraint | Rationale |
203|-----------|-----------|
204| One `.sharingRules-meta.xml` file per object | Platform requirement — multiple files cause deployment errors |
205| Guest rules must use `<guestUser>` in `sharedTo` | Using `<role>` or `<group>` causes: "Specify a guest user's nickname for the guestUser field" |
206| Account rules require `<accountSettings>` | Without it: "AccountSettings is required for account sharing rules" |
207| `includeRecordsOwnedByAll` is required on criteria rules | Missing it causes: "Required field is missing: sharingCriteriaRules" |
208| `includeHVUOwnedRecords` is required on guest rules | Missing it causes deployment failure |
209| Criteria field values must exist as picklist values on the org | Invalid values cause: "Picklist value does not exist" |
210| Never hardcode file paths — resolve from `sfdx-project.json` | Customer projects use custom package directories |
211| For managed package custom objects, use the full API name including namespace prefix (e.g., `ns__Object__c`) | Namespace-prefixed objects store sharing rules under the prefixed name |
212| `sharedTo` and `sharedFrom` cannot be edited in place | Platform does not support modifying sharing targets — deploy will fail. Delete the rule and create a new one instead |
213| Owner-based rules only support editing `accessLevel` | No other field (`label`, `sharedTo`, `sharedFrom`) can be modified on owner rules — delete and recreate instead |
214| Always retrieve from the org before edit or delete | Local files may be stale; editing a stale file can recreate deleted rules or overwrite concurrent changes |
215| Deleting a rule requires a destructive deployment | A normal deploy is additive — it will not remove rules from the org. Delegate to `platform-destructive-deploy` |
216| Edit must preserve unmodified elements | Changing only `accessLevel` must not alter `criteriaItems` or other fields |
217| Delete must remove the entire rule block | Partial deletion leaves invalid XML and causes deployment failures |
218| Delete last rule removes the file | An empty `<SharingRules>` root with no children is invalid metadata |
219
220---
221
222## Gotchas
223
224| Issue | Resolution |
225|-------|------------|
226| Guest rule uses `<role>` instead of `<guestUser>` | Replace with `<guestUser>CommunityNickname</guestUser>` |
227| Account rule missing `accountSettings` | Add `<accountSettings>` with all three access level sub-elements set to `None` |
228| Criteria rule missing `includeRecordsOwnedByAll` | Add `<includeRecordsOwnedByAll>true</includeRecordsOwnedByAll>` |
229| Picklist value mismatch | Query the org for valid values before generating criteria |
230| Appending duplicates existing rule name | Check existing `<fullName>` values before writing |
231| Guest user nickname not found | Query: `SELECT CommunityNickname FROM User WHERE UserType='Guest' AND IsActive=true` |
232| User requests edit to `sharedTo` or `sharedFrom` | Not supported — refuse the edit and instruct user to delete + create a new rule |
233| User requests edit to owner rule beyond `accessLevel` | Not supported — owner rules only allow `accessLevel` edits. Refuse and instruct user to delete + create |
234| Editing changes rule type (e.g., criteria → owner) | Not supported — delete the old rule and create a new one instead |
235| Local file is stale (rule deleted/changed in org) | Always retrieve fresh from org before edit or delete to avoid recreating removed rules |
236| Delete deployed with normal deploy (no destructive manifest) | Rule remains in the org — delegate to `platform-destructive-deploy` for proper removal |
237| Deleting a rule referenced by other automation | Warn the user about potential downstream impact |
238| Delete leaves malformed XML | Ensure proper XML structure after removal; validate the file is well-formed |
239
240---
241
242## Output Expectations
243
244Deliverables:
245- **For get operations**: `<packageDir>/sharingRules/<ObjectName>.sharingRules-meta.xml` — retrieved sharing rules file from the org, plus a formatted summary of all rules found
246- **For create/edit/delete operations**: `<packageDir>/sharingRules/<ObjectName>.sharingRules-meta.xml` — complete sharing rules file for the target object
247
248---
249
250## Cross-Skill Integration
251
252| Need | Delegate to |
253|------|-------------|
254| Permission set configuration | `platform-permission-set-generate` skill |
255| Custom object creation (if target object doesn't exist) | `platform-custom-object-generate` skill |
256| Destructive deployment (rule deletion from org) | `platform-destructive-deploy` skill |
257
258---
259
260## Reference File Index
261
262| File | When to read |
263|------|-------------|
264| `references/rule-types.md` | Phase 2 — before generating any rule, to get the complete XML schema for each rule type |
265| `scripts/count-remaining-rules.sh` | Phase 3, step 8b (Delete) — count sharing rule elements to determine if file should be removed |
266| `examples/create-cases.md` | Phase 4, step 10 — expected behavior for create and append scenarios |
267| `examples/edit-cases.md` | Phase 4, step 10 — expected behavior for edit scenarios |
268| `examples/delete-cases.md` | Phase 4, step 10 — expected behavior for delete scenarios |