LWC Experience Cloud Development
Generate production-grade Lightning Web Components for Salesforce Experience Cloud sites,
with correct meta XML configuration, proper CSS architecture, and awareness of guest user
context, sharing model implications, and Experience Builder integration patterns.
Before Writing Any Code
Determine the runtime. Ask whether the site is LWR or Aura-based if not specified.
The answer changes CSS scoping, routing, available targets, rendering behavior, and
whether SSR/hydration is available.
Read reference/lwr/experience-cloud-sites-overview.md for the differences.
Determine the user context. Is this component for guest (unauthenticated) users,
authenticated community members, or both?
Read reference/site-setup/guest-user-data-access.md for Apex sharing patterns
and reference/lwc-patterns/secure-apex-classes.md for FLS enforcement.
Determine the component's role. Is this a:
- Page component → dragged onto a page in Experience Builder
- Theme layout → wraps the entire page (header/footer/structure) — LWR only
- Page layout → defines the content area grid for an LWR page — LWR only
- Custom property editor → configures another component's properties in Builder
Each role has different meta XML targets. Read reference/lwr/lwr-sites-architecture.md
for layouts or reference/builder-ui/custom-property-editor-contract.md for CPEs.
Meta XML Configuration
Every Experience Cloud LWC needs specific targets in js-meta.xml:
Page Components (most common)
<targets>
<target>lightningCommunity__Page</target>
<target>lightningCommunity__Default</target>
</targets>
lightningCommunity__Page makes it draggable onto pages in Experience Builder
lightningCommunity__Default exposes @api properties in the property panel
- Both are required for a configurable page component
Theme Layouts (LWR only)
<targets>
<target>lightningCommunity__Theme_Layout</target>
<target>lightningCommunity__Default</target>
</targets>
Page Layouts (LWR only)
<targets>
<target>lightningCommunity__Page_Layout</target>
<target>lightningCommunity__Default</target>
</targets>
Custom Property Editors
<targets>
<target>lightning__PropertyEditor</target>
</targets>
SSR Support (LWR only)
<capabilities>
<!-- static HTML only, no client JS: -->
<capability>lightning__ServerRenderable</capability>
<!-- SSR with client-side hydration for interactivity: -->
<capability>lightning__ServerRenderableWithHydration</capability>
</capabilities>
For the complete target and capability reference, read
reference/lwc-patterns/xml-configuration-reference.md.
CSS Architecture Rules
Global/shared CSS goes in Experience Builder → Settings → Advanced → Edit Head Markup.
This is NOT the same as the Setup gear icon in the main org.
Component CSS stays scoped inside each LWC's .css file.
In LWR sites, use --dxp styling hooks for brand colors, text, and spacing. These
map to Experience Builder's Theme panel. Use --dxp-g-brand for brand color,
--dxp-g-root for background, etc.
Read reference/lwr/lwr-sites-architecture.md (--dxp Styling Hooks section).
For base component styling in LWR, use ::part() with SLDS hooks — native shadow
DOM blocks direct targeting.
Read reference/lwr/lwr-base-component-styling.md.
For SSR components, use light DOM (static renderMode = 'light').
Read reference/lwr/light-dom.md and reference/lwr/lwr-configure-components-ssr.md.
Guest User Patterns
When building components accessible to unauthenticated users:
- The guest user profile is named
[Site Name] Profile, NOT Guest User
- Object permissions AND Field-Level Security must both be configured on the profile
without sharing on Apex bypasses record sharing rules but still requires object-level
Read/Create on the guest profile
- Guest user sharing rules grant Read Only access — updates/deletes MUST use
without sharing
- Guest users can never own records — records are assigned to a default org user
- Never return raw record IDs to guest users — use encrypted tokens
- Read
reference/site-setup/guest-user-profile-setup.md for the full setup walkthrough
and reference/site-setup/guest-user-data-access.md for Apex patterns
Navigation
Use the lightning/navigation module with NavigationMixin. Experience Cloud has
different PageReference types than Lightning Experience:
comm__namedPage for EC pages (NOT standard__namedPage)
standard__recordPage requires objectApiName in LWR sites
- Only
actionName: 'view' works for records in EC (no edit or clone)
Read reference/lwc-patterns/page-reference-types.md for the complete reference.
For site navigation menus (header/footer links): use Experience Cloud's Navigation Menu
feature and pull menus dynamically into your LWC via Apex + ConnectApi, not hardcoded links.
Read reference/lwr/lwr-sites-architecture.md (Custom Navigation Menu section).
Apex Patterns for EC
- Always declare
with sharing, without sharing, or inherited sharing explicitly
@AuraEnabled(cacheable=true) for read-only methods used with @wire
@AuraEnabled (no cacheable) for DML methods called imperatively
- Use
WITH USER_MODE in SOQL for automatic FLS enforcement
- Use
AuraHandledException for clean error messages to the client
- Governor limits: 100 SOQL queries, 150 DML statements, 6MB heap (synchronous)
Read reference/lwc-patterns/apex-fundamentals-for-ec.md for the full reference including
governor limits, async patterns, and bulkification.
Site Architecture and Deployment
When planning a new LWR site or deploying Experience Cloud metadata:
Understand the layer model. Theme layouts wrap pages, page layouts define the grid,
page components fill the grid, and content.json binds them together.
Read reference/lwr/site-architecture-mental-model.md for the full mental model
including a planning template and worked example.
Know the bundle structure. DigitalExperienceBundles live under
force-app/main/default/digitalExperiences/site/<SiteName>/. Each page has three
metadata folders: sfdc_cms__appPage (content), sfdc_cms__view (layout binding),
and sfdc_cms__route (URL mapping). Each contains a content.json that defines
which components go in which regions.
Read reference/lwr/digital-experience-bundle-structure.md for the schema.
Deploy in the right order. Apex classes first, then LWC, then the
DigitalExperienceBundle, then republish. Never deploy the bundle before the
components it references — first-time deploys MUST be two separate commands.
Read reference/lwr/deploy-ordering-and-publishing.md for the full sequence.
Always republish. LWR sites use a publish-freeze model. Deployed changes are
invisible until you run sf community publish --name "SiteName" or click Publish
in Experience Builder.
Understand theme layout region contracts. The default (unnamed) slot is required.
Named slots (header, footer) are conventions, not enforced. Slot fallback content
does NOT work — the platform always projects an empty region wrapper.
Read reference/lwr/lwr-sites-architecture.md (Theme Layout Region Contract section).
Code Style
When generating code for this developer:
- Apex comments:
// with one space, disembodied narrator tone
(// begin sorting through accounts, // remember we set this for the guest profile)
- Every method: document params and return value in comments
- Debug statements: at key decision points to aid development
- No single-line conditionals except ternary
? operator
- JavaScript: more detailed comments explaining what non-obvious patterns do
- Variable names: meaningful in context, never
temp, data, result without qualifier
Reference Docs
Read the relevant reference doc BEFORE generating code:
| Topic |
File |
| EC sites overview (Aura vs LWR) |
reference/lwr/experience-cloud-sites-overview.md |
| LWR architecture (layouts, --dxp hooks, URLs, publishing) |
reference/lwr/lwr-sites-architecture.md |
| SSR hydration / Islands architecture |
reference/lwr/lwr-ssr-hydration-experience-cloud.md |
| SSR component requirements |
reference/lwr/lwr-configure-components-ssr.md |
| Base component styling in LWR |
reference/lwr/lwr-base-component-styling.md |
| Light DOM |
reference/lwr/light-dom.md |
| CMS content delivery |
reference/lwr/cms-for-experience-cloud.md |
| Custom property editors (CPE contract) |
reference/builder-ui/custom-property-editor-contract.md |
| CPE + LightningTypeBundle details |
reference/lwr/experience-builder-custom-properties.md |
| CPE considerations and limitations |
reference/lwr/custom-property-editors-considerations.md |
| Configure component for Experience Builder |
reference/builder-ui/configure-component-for-experience-builder.md |
| XML targets and capabilities (complete) |
reference/lwc-patterns/xml-configuration-reference.md |
| PageReference types for EC navigation |
reference/lwc-patterns/page-reference-types.md |
| Current community/site info modules |
reference/lwc-patterns/current-community-info.md |
| @salesforce modules reference |
reference/lwc-patterns/salesforce-modules.md |
| Permissions (guest vs auth) |
reference/lwc-patterns/lwc-permissions.md |
| Apex fundamentals (sharing, limits, async) |
reference/lwc-patterns/apex-fundamentals-for-ec.md |
| Secure Apex classes (FLS, CRUD) |
reference/lwc-patterns/secure-apex-classes.md |
| Expose Apex methods |
reference/lwc-patterns/expose-apex-methods.md |
| Wire Apex methods |
reference/lwc-patterns/wire-apex-methods.md |
| Call Apex imperatively |
reference/lwc-patterns/call-apex-imperatively.md |
| Handle errors from Apex |
reference/lwc-patterns/handle-errors-apex.md |
| RefreshView API |
reference/lwc-patterns/refreshview-api.md |
| Aura interface → LWC target mapping |
reference/lwc-patterns/migrate-interfaces-to-targets.md |
| Guest user profile setup |
reference/site-setup/guest-user-profile-setup.md |
| Guest user data access (Apex patterns) |
reference/site-setup/guest-user-data-access.md |
| Site architecture mental model (planning) |
reference/lwr/site-architecture-mental-model.md |
| DigitalExperienceBundle structure and content.json |
reference/lwr/digital-experience-bundle-structure.md |
| Deploy ordering and publishing |
reference/lwr/deploy-ordering-and-publishing.md |
| Common pitfalls |
reference/common-pitfalls.md |
Templates
Use these as starting points when generating components:
| Pattern |
Directory |
| Basic LWR page component |
templates/lwr-page-component/ |
| LWR theme layout |
templates/lwr-theme-layout/ |
| Guest-accessible form |
templates/guest-accessible-form/ |
| Meta XML examples |
templates/meta-xml-examples/ |
| DigitalExperienceBundle structure |
templates/digital-experience-bundle/ |
Checklists
Offer relevant checklists when the user is setting up or going live:
| Checklist |
File |
| New site setup |
checklists/new-site-checklist.md |
| Guest user security audit |
checklists/guest-user-audit.md |
1---2name: lwc-experience-cloud3description: Build Lightning Web Components for Salesforce Experience Cloud (Digital Experiences), including LWR sites, Aura-based community sites, and Experience Builder configuration. Use this skill whenever the user mentions Experience Cloud, Digital Experience, community site, community portal, Experience Builder, LWR site, guest user access on a portal, or any LWC development targeting lightningCommunity__Page, lightningCommunity__Default, lightningCommunity__Page_Layout, or lightningCommunity__Theme_Layout targets. Also trigger when the user asks about custom property editors for Experience Builder, theme layouts, page layouts for LWR, CSS scoping in community components, navigation menus in Experience Cloud, guest user profile configuration, DigitalExperienceBundle, content.json for Experience Cloud, deploying Experience Cloud metadata, deploy ordering for LWC sites, sfdx-project.json for community sites, site architecture planning, or ExperienceBundle structure. This skill covers code generation, Experience Builde4---56# LWC Experience Cloud Development78Generate production-grade Lightning Web Components for Salesforce Experience Cloud sites,9with correct meta XML configuration, proper CSS architecture, and awareness of guest user10context, sharing model implications, and Experience Builder integration patterns.1112## Before Writing Any Code13141. **Determine the runtime.** Ask whether the site is LWR or Aura-based if not specified.15 The answer changes CSS scoping, routing, available targets, rendering behavior, and16 whether SSR/hydration is available.17 Read `reference/lwr/experience-cloud-sites-overview.md` for the differences.18192. **Determine the user context.** Is this component for guest (unauthenticated) users,20 authenticated community members, or both?21 Read `reference/site-setup/guest-user-data-access.md` for Apex sharing patterns22 and `reference/lwc-patterns/secure-apex-classes.md` for FLS enforcement.23243. **Determine the component's role.** Is this a:25 - **Page component** → dragged onto a page in Experience Builder26 - **Theme layout** → wraps the entire page (header/footer/structure) — LWR only27 - **Page layout** → defines the content area grid for an LWR page — LWR only28 - **Custom property editor** → configures another component's properties in Builder2930 Each role has different meta XML targets. Read `reference/lwr/lwr-sites-architecture.md`31 for layouts or `reference/builder-ui/custom-property-editor-contract.md` for CPEs.3233## Meta XML Configuration3435Every Experience Cloud LWC needs specific targets in `js-meta.xml`:3637### Page Components (most common)38```xml39<targets>40 <target>lightningCommunity__Page</target>41 <target>lightningCommunity__Default</target>42</targets>43```44- `lightningCommunity__Page` makes it draggable onto pages in Experience Builder45- `lightningCommunity__Default` exposes `@api` properties in the property panel46- Both are required for a configurable page component4748### Theme Layouts (LWR only)49```xml50<targets>51 <target>lightningCommunity__Theme_Layout</target>52 <target>lightningCommunity__Default</target>53</targets>54```5556### Page Layouts (LWR only)57```xml58<targets>59 <target>lightningCommunity__Page_Layout</target>60 <target>lightningCommunity__Default</target>61</targets>62```6364### Custom Property Editors65```xml66<targets>67 <target>lightning__PropertyEditor</target>68</targets>69```7071### SSR Support (LWR only)72```xml73<capabilities>74 <!-- static HTML only, no client JS: -->75 <capability>lightning__ServerRenderable</capability>76 <!-- SSR with client-side hydration for interactivity: -->77 <capability>lightning__ServerRenderableWithHydration</capability>78</capabilities>79```8081For the complete target and capability reference, read82`reference/lwc-patterns/xml-configuration-reference.md`.8384## CSS Architecture Rules85861. **Global/shared CSS** goes in Experience Builder → Settings → Advanced → Edit Head Markup.87 This is NOT the same as the Setup gear icon in the main org.88892. **Component CSS** stays scoped inside each LWC's `.css` file.90913. **In LWR sites, use `--dxp` styling hooks** for brand colors, text, and spacing. These92 map to Experience Builder's Theme panel. Use `--dxp-g-brand` for brand color,93 `--dxp-g-root` for background, etc.94 Read `reference/lwr/lwr-sites-architecture.md` (--dxp Styling Hooks section).95964. **For base component styling in LWR**, use `::part()` with SLDS hooks — native shadow97 DOM blocks direct targeting.98 Read `reference/lwr/lwr-base-component-styling.md`.991005. **For SSR components**, use light DOM (`static renderMode = 'light'`).101 Read `reference/lwr/light-dom.md` and `reference/lwr/lwr-configure-components-ssr.md`.102103## Guest User Patterns104105When building components accessible to unauthenticated users:1061071. The guest user profile is named `[Site Name] Profile`, NOT `Guest User`1082. Object permissions AND Field-Level Security must both be configured on the profile1093. `without sharing` on Apex bypasses record sharing rules but still requires object-level110 Read/Create on the guest profile1114. Guest user sharing rules grant Read Only access — updates/deletes MUST use `without sharing`1125. Guest users can never own records — records are assigned to a default org user1136. Never return raw record IDs to guest users — use encrypted tokens1147. Read `reference/site-setup/guest-user-profile-setup.md` for the full setup walkthrough115 and `reference/site-setup/guest-user-data-access.md` for Apex patterns116117## Navigation118119Use the `lightning/navigation` module with `NavigationMixin`. Experience Cloud has120different PageReference types than Lightning Experience:121- `comm__namedPage` for EC pages (NOT `standard__namedPage`)122- `standard__recordPage` requires `objectApiName` in LWR sites123- Only `actionName: 'view'` works for records in EC (no `edit` or `clone`)124125Read `reference/lwc-patterns/page-reference-types.md` for the complete reference.126127For site navigation menus (header/footer links): use Experience Cloud's Navigation Menu128feature and pull menus dynamically into your LWC via Apex + ConnectApi, not hardcoded links.129Read `reference/lwr/lwr-sites-architecture.md` (Custom Navigation Menu section).130131## Apex Patterns for EC132133- Always declare `with sharing`, `without sharing`, or `inherited sharing` explicitly134- `@AuraEnabled(cacheable=true)` for read-only methods used with `@wire`135- `@AuraEnabled` (no cacheable) for DML methods called imperatively136- Use `WITH USER_MODE` in SOQL for automatic FLS enforcement137- Use `AuraHandledException` for clean error messages to the client138- Governor limits: 100 SOQL queries, 150 DML statements, 6MB heap (synchronous)139140Read `reference/lwc-patterns/apex-fundamentals-for-ec.md` for the full reference including141governor limits, async patterns, and bulkification.142143## Site Architecture and Deployment144145When planning a new LWR site or deploying Experience Cloud metadata:1461471. **Understand the layer model.** Theme layouts wrap pages, page layouts define the grid,148 page components fill the grid, and content.json binds them together.149 Read `reference/lwr/site-architecture-mental-model.md` for the full mental model150 including a planning template and worked example.1511522. **Know the bundle structure.** DigitalExperienceBundles live under153 `force-app/main/default/digitalExperiences/site/<SiteName>/`. Each page has three154 metadata folders: `sfdc_cms__appPage` (content), `sfdc_cms__view` (layout binding),155 and `sfdc_cms__route` (URL mapping). Each contains a `content.json` that defines156 which components go in which regions.157 Read `reference/lwr/digital-experience-bundle-structure.md` for the schema.1581593. **Deploy in the right order.** Apex classes first, then LWC, then the160 DigitalExperienceBundle, then republish. Never deploy the bundle before the161 components it references — first-time deploys MUST be two separate commands.162 Read `reference/lwr/deploy-ordering-and-publishing.md` for the full sequence.1631644. **Always republish.** LWR sites use a publish-freeze model. Deployed changes are165 invisible until you run `sf community publish --name "SiteName"` or click Publish166 in Experience Builder.1671685. **Understand theme layout region contracts.** The default (unnamed) slot is required.169 Named slots (header, footer) are conventions, not enforced. Slot fallback content170 does NOT work — the platform always projects an empty region wrapper.171 Read `reference/lwr/lwr-sites-architecture.md` (Theme Layout Region Contract section).172173## Code Style174175When generating code for this developer:176177- **Apex comments**: `// ` with one space, disembodied narrator tone178 (`// begin sorting through accounts`, `// remember we set this for the guest profile`)179- **Every method**: document params and return value in comments180- **Debug statements**: at key decision points to aid development181- **No single-line conditionals** except ternary `?` operator182- **JavaScript**: more detailed comments explaining what non-obvious patterns do183- **Variable names**: meaningful in context, never `temp`, `data`, `result` without qualifier184185## Reference Docs186187Read the relevant reference doc BEFORE generating code:188189| Topic | File |190|---|---|191| EC sites overview (Aura vs LWR) | `reference/lwr/experience-cloud-sites-overview.md` |192| LWR architecture (layouts, --dxp hooks, URLs, publishing) | `reference/lwr/lwr-sites-architecture.md` |193| SSR hydration / Islands architecture | `reference/lwr/lwr-ssr-hydration-experience-cloud.md` |194| SSR component requirements | `reference/lwr/lwr-configure-components-ssr.md` |195| Base component styling in LWR | `reference/lwr/lwr-base-component-styling.md` |196| Light DOM | `reference/lwr/light-dom.md` |197| CMS content delivery | `reference/lwr/cms-for-experience-cloud.md` |198| Custom property editors (CPE contract) | `reference/builder-ui/custom-property-editor-contract.md` |199| CPE + LightningTypeBundle details | `reference/lwr/experience-builder-custom-properties.md` |200| CPE considerations and limitations | `reference/lwr/custom-property-editors-considerations.md` |201| Configure component for Experience Builder | `reference/builder-ui/configure-component-for-experience-builder.md` |202| XML targets and capabilities (complete) | `reference/lwc-patterns/xml-configuration-reference.md` |203| PageReference types for EC navigation | `reference/lwc-patterns/page-reference-types.md` |204| Current community/site info modules | `reference/lwc-patterns/current-community-info.md` |205| @salesforce modules reference | `reference/lwc-patterns/salesforce-modules.md` |206| Permissions (guest vs auth) | `reference/lwc-patterns/lwc-permissions.md` |207| Apex fundamentals (sharing, limits, async) | `reference/lwc-patterns/apex-fundamentals-for-ec.md` |208| Secure Apex classes (FLS, CRUD) | `reference/lwc-patterns/secure-apex-classes.md` |209| Expose Apex methods | `reference/lwc-patterns/expose-apex-methods.md` |210| Wire Apex methods | `reference/lwc-patterns/wire-apex-methods.md` |211| Call Apex imperatively | `reference/lwc-patterns/call-apex-imperatively.md` |212| Handle errors from Apex | `reference/lwc-patterns/handle-errors-apex.md` |213| RefreshView API | `reference/lwc-patterns/refreshview-api.md` |214| Aura interface → LWC target mapping | `reference/lwc-patterns/migrate-interfaces-to-targets.md` |215| Guest user profile setup | `reference/site-setup/guest-user-profile-setup.md` |216| Guest user data access (Apex patterns) | `reference/site-setup/guest-user-data-access.md` |217| Site architecture mental model (planning) | `reference/lwr/site-architecture-mental-model.md` |218| DigitalExperienceBundle structure and content.json | `reference/lwr/digital-experience-bundle-structure.md` |219| Deploy ordering and publishing | `reference/lwr/deploy-ordering-and-publishing.md` |220| Common pitfalls | `reference/common-pitfalls.md` |221222## Templates223224Use these as starting points when generating components:225226| Pattern | Directory |227|---|---|228| Basic LWR page component | `templates/lwr-page-component/` |229| LWR theme layout | `templates/lwr-theme-layout/` |230| Guest-accessible form | `templates/guest-accessible-form/` |231| Meta XML examples | `templates/meta-xml-examples/` |232| DigitalExperienceBundle structure | `templates/digital-experience-bundle/` |233234## Checklists235236Offer relevant checklists when the user is setting up or going live:237238| Checklist | File |239|---|---|240| New site setup | `checklists/new-site-checklist.md` |241| Guest user security audit | `checklists/guest-user-audit.md` |