Skip to content
platform-sharing-rules-generate logo

Sharing Rules Generator

platform-sharing-rules-generate

Use this skill when users need to 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 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).

forcedotcom/sf-skills5.7Kinstalls1.1Kstars

SKILL.md

Full skill instructions

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

  1. Resolve the SFDX project path — find the project's sfdx-project.json and identify the package directory for sharingRules/.

  2. 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.

  3. 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

  1. Identify the operation — determine whether the user wants to get, create, edit, or delete a sharing rule.

  2. Select the rule type based on user intent. Read references/​rule-types.md for the complete schema of each type and its required elements.

  3. For Account sharing rules: the accountSettings element is required. Default sub-access levels to None unless the user specifies otherwise.

  4. 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

  1. 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.
  2. 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

  • Does the file have the XML declaration and <SharingRules xmlns="http://soap.sforce.com/​2006/​04/​metadata"> root?
  • Is there exactly one file per object with all rules inside it?
  • Does <fullName> use PascalCase with no spaces?
  • Is <label> present and human-readable?
  • Is <accessLevel> one of Read or Edit?

Criteria Rule Checks

  • Is <includeRecordsOwnedByAll> present (required boolean)?
  • Does each <criteriaItems> have <field>, <operation>, and <value>?
  • Are picklist values valid for the target org?

Guest Rule Checks CRITICAL

  • Does <sharedTo> use <guestUser> (NOT <role> or <group>)?
  • Is <includeHVUOwnedRecords> present (required boolean)?
  • Is <includeRecordsOwnedByAll> ABSENT (only for criteria rules, not guest rules)?

Owner Rule Checks

  • Does the rule have both <sharedFrom> and <sharedTo> elements?
  • Do both use valid <role>, <roleAndSubordinates>, or <group> targets?

Edit Operation Checks

  • Was the edit against a freshly retrieved file (not a stale local copy)?
  • Is the edit limited to supported fields for the rule type?
    • Owner rules: only accessLevel
    • Criteria rules: accessLevel, criteriaItems, label, booleanFilter
    • Guest rules: accessLevel, criteriaItems, label, includeHVUOwnedRecords
  • Was sharedTo/sharedFrom left unchanged? (if user requested that change, refuse and advise delete + create)
  • Was only the intended element modified?
  • Are all required elements still present after the edit?
  • Does the modified rule still pass the universal checks above?

Delete Operation Checks

  • Was the correct rule removed (matched by <fullName>)?
  • Is the remaining XML well-formed with proper <SharingRules> root?
  • If no rules remain, was the file removed entirely?
  • Was platform-destructive-deploy delegated to with the correct metadata type (SharingCriteriaRule, SharingOwnerRule, or SharingGuestRule)?

Account-Specific Checks CRITICAL

  • If object is Account, is <accountSettings> present with all three sub-elements?
  • Are <caseAccessLevel>, <contactAccessLevel>, <opportunityAccessLevel> all set?

Rules / Constraints

ConstraintRationale
One .sharingRules-meta.xml file per objectPlatform requirement — multiple files cause deployment errors
Guest rules must use <guestUser> in sharedToUsing <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 rulesMissing it causes: "Required field is missing: sharingCriteriaRules"
includeHVUOwnedRecords is required on guest rulesMissing it causes deployment failure
Criteria field values must exist as picklist values on the orgInvalid values cause: "Picklist value does not exist"
Never hardcode file paths — resolve from sfdx-project.jsonCustomer 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 placePlatform does not support modifying sharing targets — deploy will fail. Delete the rule and create a new one instead
Owner-based rules only support editing accessLevelNo other field (label, sharedTo, sharedFrom) can be modified on owner rules — delete and recreate instead
Always retrieve from the org before edit or deleteLocal files may be stale; editing a stale file can recreate deleted rules or overwrite concurrent changes
Deleting a rule requires a destructive deploymentA normal deploy is additive — it will not remove rules from the org. Delegate to platform-destructive-deploy
Edit must preserve unmodified elementsChanging only accessLevel must not alter criteriaItems or other fields
Delete must remove the entire rule blockPartial deletion leaves invalid XML and causes deployment failures
Delete last rule removes the fileAn empty <SharingRules> root with no children is invalid metadata

Gotchas

IssueResolution
Guest rule uses <role> instead of <guestUser>Replace with <guestUser>CommunityNickname</​guestUser>
Account rule missing accountSettingsAdd <accountSettings> with all three access level sub-elements set to None
Criteria rule missing includeRecordsOwnedByAllAdd <includeRecordsOwnedByAll>true</​includeRecordsOwnedByAll>
Picklist value mismatchQuery the org for valid values before generating criteria
Appending duplicates existing rule nameCheck existing <fullName> values before writing
Guest user nickname not foundQuery: SELECT CommunityNickname FROM User WHERE UserType='Guest' AND IsActive=true
User requests edit to sharedTo or sharedFromNot supported — refuse the edit and instruct user to delete + create a new rule
User requests edit to owner rule beyond accessLevelNot 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 automationWarn the user about potential downstream impact
Delete leaves malformed XMLEnsure 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

NeedDelegate to
Permission set configurationplatform-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

FileWhen to read
references/​rule-types.mdPhase 2 — before generating any rule, to get the complete XML schema for each rule type
scripts/​count-remaining-rules.shPhase 3, step 8b (Delete) — count sharing rule elements to determine if file should be removed
examples/​create-cases.mdPhase 4, step 10 — expected behavior for create and append scenarios
examples/​edit-cases.mdPhase 4, step 10 — expected behavior for edit scenarios
examples/​delete-cases.mdPhase 4, step 10 — expected behavior for delete scenarios

More skills from forcedotcom

platform-apex-logs-debug logo
forcedotcom/sf-skills

platform-apex-logs-debug

Salesforce debug log analysis and troubleshooting with 100-point scoring. TRIGGER when: user analyzes debug logs, hits governor limits, reads stack traces, or touches .log files from Salesforce orgs. DO NOT TRIGGER when: running Apex tests (use platform-apex-test-run), generating or fixing Apex code (use platform-apex-generate), or Agentforce session tracing (use agentforce-observe).

1.1K 6.4K
View
platform-soql-query logo
forcedotcom/sf-skills

platform-soql-query

SOQL query generation, optimization, and analysis with 100-point scoring. Use this skill when the user needs SOQL/SOSL authoring or optimization: natural-language-to-query generation, relationship queries, aggregates, query-plan analysis, and performance or safety improvements for Salesforce queries. TRIGGER when: user writes, optimizes, or debugs SOQL/SOSL queries, touches .soql files, or asks about relationship queries, aggregates, or query performance. DO NOT TRIGGER when: bulk data operations (use platform-data-manage), Apex DML logic (use platform-apex-generate), or report/dashboard queries.

1.1K 6.3K
View
platform-metadata-deploy logo
forcedotcom/sf-skills

platform-metadata-deploy

Salesforce DevOps automation using sf CLI v2. TRIGGER when: user deploys metadata, creates/manages scratch orgs or sandboxes, sets up CI/CD pipelines, or troubleshoots deployment errors with sf project deploy. DO NOT TRIGGER when: writing Apex code (use platform-apex-generate), building LWC components (use experience-lwc-generate), creating metadata definitions (use platform-custom-object-generate or platform-custom-field-generate), or querying org data (use platform-data-manage).

1.1K 6.3K
View
platform-metadata-retrieve logo
forcedotcom/sf-skills

platform-metadata-retrieve

ALWAYS USE THIS SKILL to retrieve metadata from an org to your local project using the sf project retrieve start command. Supports multiple retrieval modes: retrieve all remote changes, retrieve by source directory, retrieve by metadata type with wildcards, retrieve by manifest (package.xml), or retrieve by package name. Use when the user asks to retrieve, pull, sync, or download metadata, Apex classes, custom objects, or org changes. Supports source format (default) or metadata format (ZIP). DO NOT TRIGGER for deploying metadata (use platform-metadata-deploy skill), listing metadata, or generating package.xml. NEVER use MCP tools - always use this skill and the Bash tool with sf project retrieve start.

1.1K 6.3K
View
platform-custom-field-generate logo
forcedotcom/sf-skills

platform-custom-field-generate

Use this skill when users need to create, generate, or validate Salesforce Custom Field metadata. Trigger when users mention custom fields, field types, Roll-up Summary fields, Master-Detail relationships, Lookup relationships, formula fields, picklists, dependent (controlling) picklists, referencing a value set from a field, or scoping/limiting picklist values for a specific record type. Also use when users encounter field deployment errors, especially around Roll-up Summary format, Master-Detail constraints, formula issues, or a record type that won't deploy without a business process. Use this skill for custom field metadata work, field generation, and field troubleshooting. DO NOT TRIGGER for creating or customizing the value set itself — defining a new GlobalValueSet, or modifying a StandardValueSet catalog like Industry or Lead Source — use platform-value-set-generate instead; this skill covers the field that references a value set, not the value set definition.

1.1K 6.2K
View

Generates correct, deployable Salesforce permission set metadata (PermissionSet XML) with object, field, user, and app permissions. Use this skill when creating or editing permission set metadata, object permissions, field-level security (FLS), tab visibility, or deploying permission sets.

1.1K 6.1K
View
dx-code-analyzer-run logo
forcedotcom/sf-skills

dx-code-analyzer-run

Run Salesforce Code Analyzer to scan code for security, performance, best practice, and code style violations. Supports all engines (PMD, ESLint, CPD, RetireJS, Flow, SFGE, ApexGuru), targets (files, folders, git diff), categories, and severities. Also handles post-scan exploration: filtering results by engine/severity/category/file, and explaining what rules mean. TRIGGER when: user says 'scan my code', 'check security issues', 'run PMD/ESLint', 'find duplicates', 'analyze Flows', 'check vulnerable libraries', 'AppExchange review', 'lint my LWC', 'static analysis', 'code quality', 'show security violations', 'what is this rule', 'explain ApexCRUDViolation', 'filter results', or mentions engines/file types (.cls, .trigger, .js, .flow-meta.xml). Use this skill for scanning, exploring results, and listing rules. DO NOT TRIGGER when: user asks only about installation/configuration (use dx-code-analyzer-configure), or wants to create a custom rule (use dx-code-analyzer-custom-rule-create).

1.1K 6.1K
View
automation-flow-generate logo
forcedotcom/sf-skills

automation-flow-generate

Generate Salesforce Flows using the MCP tool execute_metadata_action. Use when the user asks to create, build, or generate a flow — including Screen, Autolaunched, Record-Triggered (before/after-save), Scheduled. Also trigger for flow-like requests such as "when a record is created", "trigger daily at", "send an email when", "update the field when", "automate", "workflow", or "flow XML/metadata". This is the only skill for Salesforce Flow generation.

1.1K 6K
View
platform-custom-object-generate logo
forcedotcom/sf-skills

platform-custom-object-generate

Use this skill when users need to create, generate, or validate Salesforce Custom Object metadata. Trigger when users mention custom objects, creating objects, object metadata, .object files, sharing models, name fields, or validation rules on objects. Also use when users say things like "create a custom object", "generate object metadata", "set up an object for...", or when they're troubleshooting object deployment errors especially around sharing models and Master-Detail relationships. Always use this skill for any custom object metadata work, including enriching and keeping the object's description current whenever its fields or validation rules change. Do NOT use this skill for non-Custom-Object metadata (Apex, Flows, LWC, Permission Sets, Custom Metadata Types) or for standard Salesforce objects.

1.1K 6K
View
platform-data-manage logo
forcedotcom/sf-skills

platform-data-manage

Salesforce data operations with 130-point scoring. Use this skill to create, update, delete, bulk import/export, generate test data, and clean up org records using sf CLI and anonymous Apex. TRIGGER when: user creates test data, performs bulk import/export, uses sf data CLI commands, needs data factory patterns for Apex tests, or needs to seed/clean records in a Salesforce org. DO NOT TRIGGER when: SOQL query writing only (use platform-soql-query), Apex test execution (use platform-apex-test-run), or metadata deployment (use platform-metadata-deploy).

1.1K 5.9K
View
experience-lwc-generate logo
forcedotcom/sf-skills

experience-lwc-generate

Lightning Web Components with PICKLES methodology and 165-point scoring. Use this skill when the user creates or edits LWC components, builds wire service patterns, or writes Jest tests for LWC. TRIGGER when: user creates/edits LWC components, touches lwc/**/*.js, .html, .css, .js-meta.xml files, or asks about wire service, SLDS, or Jest LWC tests. DO NOT TRIGGER when: Apex classes (use platform-apex-generate), Aura components, or Visualforce.

1.1K 5.9K
View
design-systems-slds-apply logo
forcedotcom/sf-skills

design-systems-slds-apply

Apply SLDS-compliant UI using the correct blueprints, styling hooks, utility classes, and icons. Use when building any UI that needs SLDS, choosing between Lightning Base Components and SLDS Blueprints, applying styling hooks for theming, using utility classes for layout and spacing, or selecting icons. Triggers include "build a modal", "create a form", "data table", "SLDS styling", "style with hooks", "add an icon".

1.1K 5.8K
View

Popular AI tools

Kaiber logo
Video

Kaiber

Generate, edit, and beat-sync AI video with leading models in one workspace.

Paid
View
Vimcal logo
Productivity

Vimcal

The world's fastest calendar for remote work

Free
View

Transform Your Design with AI Designer by ImgCreator.ai

Freemium
View
Akool AI logo
Content & writing

Akool AI

Revolutionizing Video Production with AI-Powered Creativity

Paid
View

Extend an image past the frame and let AI fill the new aspect ratio.

Freemium
View
StarByFace logo
Security

StarByFace

Discover your celebrity doppelgänger with StarByFace!

Free
View
C

ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.

Freemium
View
Opus Clip logo
Coding & apps

Opus Clip

Opus.ai: Revolutionize Your Web Experience

Free
View