Sub topic 1
Experience Cloud sites and where LWC fits
An Experience Cloud site is a website built on a Salesforce org. Customers, partners, and anonymous visitors use it to see Salesforce data without having a standard Salesforce login. This chapter explains how a site is put together and where a Lightning web component (LWC) fits in it.
Prerequisites
This chapter assumes you already have:
- Basic LWC structure: an HTML template, a JavaScript class, and a meta file.
- JavaScript fundamentals, including ES modules, classes, and decorators.
- Basic Apex and SOQL.
- Salesforce data model basics: objects, profiles, and sharing.
- The Salesforce CLI and a Salesforce DX project.
What a site is made of
A site is a set of pages, each built from components. Salesforce supplies standard components, such as headers, record lists, and search boxes. You can add your own LWCs next to them.
Three parts matter most:
- The site runtime. This is the engine that serves pages to visitors. Aura sites and LWR sites are the two choices. The next chapter compares them.
- Experience Builder. This is the visual editor where an admin arranges components on a page, sets their properties, and publishes the site.
- Site users. Visitors are either guest users, who are not logged in, or external users, who log in with a license made for sites. Both have far less access than an internal user.
Where your component runs
An LWC on a site is the same kind of component you already write. It has a template, a class, and a meta file. Three things differ:
- The meta file must expose the component to Experience Builder. Otherwise the admin cannot drag it onto a page.
- The component runs as a site user. Every Apex call, wire adapter, and record read is checked against that user's permissions.
- The component runs inside a site runtime. The runtime sets rules for navigation, styling, and the features you can use.
Common errors at this stage
These mistakes cause most early problems on sites:
- Testing only as an admin. A component can work in your org and show nothing to a guest user. Always test with the user type that will use it.
- Treating a site like an internal app. Internal users see many objects and fields by default. Site users see only what their profile, permission sets, and sharing rules grant.
- Forgetting to publish. Changes made in Experience Builder are not visible to visitors until the site is published. Deploying a component also does not publish the site.
- Assuming Aura features exist everywhere. Some Aura-based features are unavailable on LWR sites. Check the runtime before you design the component.
Where this tutorial goes next
The later chapters follow the order of a real project. You will pick a runtime, expose a component, add editable properties, read user context, and fetch data through Apex. After that you will secure the data for guest and external users. Each step builds on the idea above: your component runs as a limited site user inside a specific runtime.
Exercise
A component displays a list of Case records correctly when you test as an admin. After the site is published, a guest visitor sees an empty list. Give two likely causes that are specific to sites.
Show answer
The guest user's profile or sharing settings may not grant access to Case records or fields, so the query returns nothing. The Apex class may also not be enabled for the guest user profile. Either one makes the component work for an admin and return no data for a guest. A third cause is that the visitor is viewing an older published version of the site that does not yet contain your changes.