mirror of
https://github.com/forcedotcom/afv-library.git
synced 2026-08-04 06:07:12 +08:00
fix(generating-experience-lwr-site): ensure skill load for guest sharing rule Made-with: Cursor Co-authored-by: Hemant Singh Bisht <hsinghbisht@salesforce.com>
2.3 KiB
2.3 KiB
Guest User Sharing Rules (Public Sites Only)
Use when the user asks to create or modify a guest sharing rule, mentions a username containing "Guest User" or "Site Guest User" (e.g. "ZenLease Site Guest User"), or wants to share object records with unauthenticated visitors.
Steps
- Resolve the guest user identity: If the user provides a username like "ZenLease Site Guest User", use it directly as the
<guestUser>value (CommunityNickname). If a user ID is provided (e.g.005AAC00003f8EP), query the org to get theCommunityNicknamefirst. - Check for existing file: Look for
sharingRules/{ObjectName}.sharingRules-meta.xmllocally. If missing, retrieve it from the org before editing. - Generate the rule: Follow the XML example and critical requirements below. Never use
sharingCriteriaRulesor<role>/<group>for guest rules.
If sharingRules metadata is not available locally in force-app/main/default/sharingRules, retrieve it from the org before creating new rules.
Retrieve Full SharingRules Schema
Use the metadata MCP tool with metadataType "SharingRules" to retrieve schema.
XML Example
<?xml version="1.0" encoding="UTF-8"?>
<SharingRules xmlns="http://soap.sforce.com/2006/04/metadata">
<sharingGuestRules>
<fullName>ShareAccountsWithSiteGuest</fullName>
<accessLevel>Read</accessLevel>
<includeHVUOwnedRecords>false</includeHVUOwnedRecords>
<label>Share Accounts With Site Guest</label>
<sharedTo>
<guestUser>[site Guest User's CommunityNickanme]</guestUser>
</sharedTo>
<criteriaItems>
<field>Name</field>
<operation>notEqual</operation>
<value>null</value>
</criteriaItems>
</sharingGuestRules>
</SharingRules>
Critical Requirements
- SharedTo Element: Must use
<guestUser>{site Guest User's CommunityNickanme}</guestUser>(not URL path prefix). - includeHVUOwnedRecords: Required field. Set to
falseunless records owned by high-volume site users should be included. - One XML file per object: Put all rules for a given object in one file. Do not create additional.
Common Mistakes
- Using
<role>or<group>instead of<guestUser>in sharedTo - Omitting the required
includeHVUOwnedRecordsfield - Using
includeRecordsOwnedByAll(that's forsharingCriteriaRules, not guest rules)