Generates, retrieves, edits, and deletes Salesforce Sharing Rules metadata for record-level access control. Handles criteria-based, owner-based, and guest user rules.
Ships in sf-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them; scripts run unread.
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.
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.platform-permission-set-generate), territory-based sharing rules.Before proceeding, confirm with the user if not already clear:
sharedTo and sharedFrom cannot be edited in place)Gather or infer before proceeding:
Account, Property__c)sharingCriteriaRules, sharingOwnerRules, or sharingGuestRulesRead or Edit (maps to Read-Only or Read/Write)Defaults unless specified:
ReadincludeRecordsOwnedByAll: true for criteria rulesincludeHVUOwnedRecords: false for guest rulesaccountSettings with all sub-access levels set to NoneSteps 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).
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.
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.
A queue can't be the shared-to target. A queue is valid only as the <sharedFrom> of an owner rule (records owned by the queue). If the user asks to share records with a queue, or the shared-with name doesn't resolve as a role or public group, check whether it is a queue:
sf data query --query "SELECT Id, DeveloperName, Name FROM Group WHERE Type = 'Queue' AND (DeveloperName = '<name>' OR Name = '<name>')" --target-org <org>
If it is a queue, stop before writing any file: tell the user a sharing rule can't share records with a queue, and offer a public group with the same members or a role instead. Never put a queue in <sharedTo>, as <queue> or <group>: the deploy fails with "field integrity exception: unknown (invalid user or group)".
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.
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.
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>.
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
Apply the change:
<packageDir>/sharingRules/<ObjectName>.sharingRules-meta.xml.<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.
<SharingRules xmlns="http://soap.sforce.com/2006/04/metadata"> root?<fullName> use PascalCase with no spaces?<label> present and human-readable?<accessLevel> one of Read or Edit?<sharedTo> free of queues (no <queue>, and no queue name in <group>)?<includeRecordsOwnedByAll> present (required boolean)?<criteriaItems> have <field>, <operation>, and <value>?<sharedTo> use <guestUser> (NOT <role> or <group>)?<includeHVUOwnedRecords> present (required boolean)?<includeRecordsOwnedByAll> ABSENT (only for criteria rules, not guest rules)?<sharedFrom> and <sharedTo> elements?<role>, <roleAndSubordinates>, or <group> targets? (<sharedFrom> may also use <queue>; <sharedTo> never can)accessLevelaccessLevel, criteriaItems, label, booleanFilteraccessLevel, criteriaItems, label, includeHVUOwnedRecordssharedTo/sharedFrom left unchanged? (if user requested that change, refuse and advise delete + create)<fullName>)?<SharingRules> root?platform-destructive-deploy delegated to with the correct metadata type (SharingCriteriaRule, SharingOwnerRule, or SharingGuestRule)?<accountSettings> present with all three sub-elements?<caseAccessLevel>, <contactAccessLevel>, <opportunityAccessLevel> all set?| 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" |
A queue can't be a sharedTo target | Queues are valid only in sharedFrom of owner rules. A queue in sharedTo (as <queue> or <group>) fails at deploy with: "field integrity exception: unknown (invalid user or group)" |
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 |
| Issue | Resolution |
|---|---|
Guest rule uses <role> instead of <guestUser> | Replace with <guestUser>CommunityNickname</guestUser> |
| User asks to share records with a queue | Not supported — don't write the rule. Explain that a queue can only be the owned-by side of an owner rule, and offer a public group with the same members or a role |
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 |
Deliverables:
<packageDir>/sharingRules/<ObjectName>.sharingRules-meta.xml — retrieved sharing rules file from the org, plus a formatted summary of all rules found<packageDir>/sharingRules/<ObjectName>.sharingRules-meta.xml — complete sharing rules file for the target object| 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 |
| 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 |
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
salesforce-sharing, record-access, metadata-api, sharing-rules
/sf-skills:platform-sharing-rules-generatefrom sf-skills
sf-skills@sf-skills-plugin is listed by ccmalcom/sf-skills-plugin — review the source before installing
npx claudepluginhub ccmalcom/sf-skills-plugin --plugin sf-skills266 skills in this plugin
/afcc-setup-coordinateOrchestrates end-to-end headless setup of Agentforce Contact Center (AFCC) on a Salesforce org. Scans the org first, presents a delta plan for approval, then sequentially provisions demo users, Omni-Channel base settings, a human queue with routing config and members, presence statuses, permission sets, a PSTN voice number, and an active PstnVoice MessagingChannel wired to the queue. Interactive at key decision points — never assumes country, number type, queue names, or user counts. TRIGGER: set up AFCC, configure Agentforce Contact Center, stand up voice contact center, AFCC migration setup, provision AFCC org headlessly./agentforce-architecture-analyzeDeclared architecture snapshot for one Agentforce agent: planner, topics, actions, flows, Apex, prompt templates, and NGA plugins. Renders a human-readable architecture document and Mermaid invocation graph from design-time metadata (not runtime audit rows). TRIGGER when user asks to describe, diagram, inventory, audit, document, or diff (e.g. v3 vs v5) the architecture / action tree / topic structure / tool inventory of a specific agent by agent API name in a specific org. DO NOT TRIGGER for runtime session traces, conversation transcripts, generation timings, or gateway audit chains — this skill reads design-time metadata only (use agentforce-d360-analyze for session traces).3 plugins in 2 repositories ship this exact skill · first indexed Nov 14, 2026
Other plugins' skills for the same job