Agent Skillsforcedotcom/sf-skills › platform-sharing-rules-generate

platform-sharing-rules-generate

GitHub

用于生成和修改Salesforce Sharing Rules元数据,支持基于条件、角色/组或访客用户的记录级访问控制。涵盖创建、检索及追加规则至XML文件,适用于Experience Site配置。

skills/platform-sharing-rules-generate/SKILL.md forcedotcom/sf-skills

Trigger Scenarios

用户提及共享规则或记录共享需求 需要配置超出组织默认宽度的记录级访问权限 要求为特定角色、组或访客用户设置可见性 涉及sharingRules或.sharingRules-meta.xml文件操作

Install

npx skills add forcedotcom/sf-skills --skill platform-sharing-rules-generate -g -y
More Options

Use without installing

npx skills use forcedotcom/sf-skills@platform-sharing-rules-generate

指定 Agent (Claude Code)

npx skills add forcedotcom/sf-skills --skill platform-sharing-rules-generate -a claude-code -g -y

安装 repo 全部 skill

npx skills add forcedotcom/sf-skills --all -g -y

预览 repo 内 skill

npx skills add forcedotcom/sf-skills --list

SKILL.md

Frontmatter
{
    "name": "platform-sharing-rules-generate",
    "metadata": {
        "version": "1.0"
    },
    "description": "Use this skill when users need to create, generate, or modify Salesforce Sharing Rules metadata. TRIGGER when: users mention sharing rules, record sharing, criteria-based sharing, role-based sharing, guest user sharing, portal 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 configure record-level access beyond org-wide defaults (OWD), share object records with roles, groups, or guest users, or set up Experience Site guest user record visibility. SKIP 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)."
}

Sharing Rules Generator

Generate 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: Generating sharingCriteriaRules, sharingOwnerRules, and sharingGuestRules metadata; retrieving existing sharing rules from an org; appending new rules to existing 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 generating, confirm with the user if not already clear:

  • 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?

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

All steps are sequential. Do not skip or reorder.

Phase 1 — Discover

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

  2. Check for existing sharing rules — look for <packageDir>/sharingRules/<ObjectName>.sharingRules-meta.xml. If found, read it to understand existing rules and avoid duplicates.

  3. If no local file exists, retrieve from the org:

    sf project retrieve start --metadata "SharingRules:<ObjectName>" --target-org <org>
    

Phase 2 — Determine Rule Type

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

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

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

  1. 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
  2. Name the rule — derive <fullName> from the intent (PascalCase, no spaces, descriptive). Generate a matching <label> in Title Case with spaces.

  3. Write the file to <packageDir>/sharingRules/<ObjectName>.sharingRules-meta.xml.

Phase 4 — Verify

  1. Run the verification checklist below 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?

Account-Specific Checks CRITICAL

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

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

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

Output Expectations

Deliverables:

  • <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

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

Version History

  • 1.29.0 Current 2026-07-05 18:51

Same Skill Collection

skills/automation-flow-generate/SKILL.md
skills/commerce-b2b-open-code-components-integrate/SKILL.md
skills/commerce-b2b-store-create/SKILL.md
skills/data360-activate/SKILL.md
skills/data360-code-extension-generate/SKILL.md
skills/data360-prepare/SKILL.md
skills/data360-schema-get/SKILL.md
skills/design-systems-slds-apply/SKILL.md
skills/dx-org-permission-set-assign/SKILL.md
skills/dx-org-switch/SKILL.md
skills/experience-lwc-generate/SKILL.md
skills/experience-ui-bundle-features-generate/SKILL.md
skills/experience-ui-bundle-file-upload-generate/SKILL.md
skills/experience-ui-bundle-metadata-generate/SKILL.md
skills/experience-ui-bundle-site-generate/SKILL.md
skills/external-diagram-visual-generate/SKILL.md
skills/platform-apex-logs-debug/SKILL.md
skills/platform-custom-application-generate/SKILL.md
skills/platform-custom-tab-generate/SKILL.md
skills/platform-lightning-app-coordinate/SKILL.md
skills/platform-list-view-generate/SKILL.md
skills/platform-metadata-deploy/SKILL.md
skills/platform-permission-set-generate/SKILL.md
skills/platform-validation-rule-generate/SKILL.md
skills/agentforce-architecture-analyze/SKILL.md
skills/agentforce-d360-analyze/SKILL.md
skills/agentforce-generate/SKILL.md
skills/agentforce-observe/SKILL.md
skills/agentforce-test/SKILL.md
skills/commerce-b2b-open-code-components-replace/SKILL.md
skills/data360-connect/SKILL.md
skills/data360-harmonize/SKILL.md
skills/data360-orchestrate/SKILL.md
skills/data360-query/SKILL.md
skills/data360-segment/SKILL.md
skills/design-systems-slds-validate/SKILL.md
skills/design-systems-slds2-migrate/SKILL.md
skills/dx-app-analytics-query/SKILL.md
skills/dx-code-analyzer-configure/SKILL.md
skills/dx-code-analyzer-custom-rule-create/SKILL.md
skills/dx-code-analyzer-run/SKILL.md
skills/dx-devops-test-failures-analyze/SKILL.md
skills/dx-devops-test-pipeline-configure/SKILL.md
skills/dx-devops-test-suite-assignments-configure/SKILL.md
skills/dx-devops-test-suite-run/SKILL.md
skills/dx-org-manage/SKILL.md
skills/experience-cms-brand-apply/SKILL.md
skills/experience-content-media-search/SKILL.md
skills/experience-ui-bundle-agentforce-client-generate/SKILL.md
skills/experience-ui-bundle-app-coordinate/SKILL.md
skills/experience-ui-bundle-custom-app-generate/SKILL.md
skills/experience-ui-bundle-deploy/SKILL.md
skills/experience-ui-bundle-frontend-generate/SKILL.md
skills/experience-ui-bundle-salesforce-data-access/SKILL.md
skills/external-diagram-mermaid-generate/SKILL.md
skills/integration-connectivity-connected-app-configure/SKILL.md
skills/integration-connectivity-generate/SKILL.md
skills/integration-eventing-cdc-configure/SKILL.md
skills/integration-eventing-subscription-configure/SKILL.md
skills/mobile-apps-create/SKILL.md
skills/mobile-platform-native-capabilities-integrate/SKILL.md
skills/mobile-platform-offline-validate/SKILL.md
skills/omnistudio-callable-apex-generate/SKILL.md
skills/omnistudio-datamapper-generate/SKILL.md
skills/omnistudio-datapacks-deploy/SKILL.md
skills/omnistudio-dependencies-analyze/SKILL.md
skills/omnistudio-epc-catalog-generate/SKILL.md
skills/omnistudio-flexcard-generate/SKILL.md
skills/omnistudio-integration-procedure-generate/SKILL.md
skills/omnistudio-omniscript-generate/SKILL.md
skills/platform-agentexchange-partner-offers-configure/SKILL.md
skills/platform-agentsetup-categories-fetch/SKILL.md
skills/platform-apex-generate/SKILL.md
skills/platform-apex-test-generate/SKILL.md
skills/platform-apex-test-run/SKILL.md
skills/platform-custom-field-generate/SKILL.md
skills/platform-custom-lightning-type-generate/SKILL.md
skills/platform-custom-object-generate/SKILL.md
skills/platform-data-manage/SKILL.md
skills/platform-docs-get/SKILL.md
skills/platform-flexipage-generate/SKILL.md
skills/platform-metadata-api-context-get/SKILL.md
skills/platform-metadata-retrieve/SKILL.md
skills/platform-soql-query/SKILL.md
skills/platform-tracing-agentforce-configure/SKILL.md
skills/platform-tracing-configure/SKILL.md
skills/platform-trust-archive-manage/SKILL.md
skills/platform-value-set-generate/SKILL.md

Metadata

Files
0
Version
1.29.0
Hash
fb186578
Indexed
2026-07-05 18:51

trang chủ - Wiki
Copyright © 2011-2026 iteam. Current version is 2.155.2. UTC+08:00, 2026-07-09 06:19
浙ICP备14020137号-1 $bản đồ khách truy cập$