Sub topic 15
Deploying components and publishing the site
An Experience Cloud site has two parts to ship. The first is your code and configuration: Lightning web components, Apex, permissions, and the site definition. The second is the published copy of the site that visitors see. This chapter covers how to move both from a development org to a test or production org, and what each step does.
Prerequisites
This chapter assumes you can:
- Run
sfcommands from a Salesforce DX project. - Read a
package.xmlmanifest. - Explain how a component is exposed in Experience Builder, which earlier chapters covered. The
CaseListcomponent and itsCaseListControllerApex class are the running example.
Draft and live are separate
A site has a draft state and a published state. Experience Builder edits the draft. Visitors, including guests, see the last published version.
Deploying metadata changes the draft side and the org's code. It does not push anything to visitors on its own. Publishing is a separate action that takes a snapshot of the draft and makes it live.
Treat "deployed" and "published" as two separate states. A common first-release bug is that the component works in the builder preview but not on the live URL, because nobody published or because the guest profile was not deployed.
What belongs in the deployment
A working site depends on more than the component bundle. The table lists the metadata types you normally deploy together.
| Metadata type | What it carries |
|---|---|
| `LightningComponentBundle` | Your LWC files, including the meta file with its targets and properties |
| `ApexClass` | Controllers such as `CaseListController` |
| `ExperienceBundle` | Pages, theme and branding settings, and the component placements and property values you set in the builder |
| `Network` | Site settings such as the URL path prefix and login behavior |
| `CustomSite` | The site record and its guest user configuration |
| `Profile` or `PermissionSet` | Apex class access, object and field permissions, and the guest user profile |
| `StaticResource` and `CustomLabels` | Assets and translatable text that your components import |
ExperienceBundle is the metadata type for Experience Builder sites. LWR sites always use it. For Aura sites, Setup has a setting that enables the ExperienceBundle Metadata API. If it is off, the site is stored in an older format, so enable the setting before you plan automated deployments.
Site names can be confusing. The ExperienceBundle folder name is usually the site's API name plus a number, such as My_Support_Site1. The Network name is the site label. Retrieve a site from a real org first and copy the names you get back. Do not guess them.
sf project retrieve start \
--metadata ExperienceBundle:My_Support_Site1 \
--metadata "Network:My Support Site" \
--metadata CustomSite:My_Support_Site \
--target-org devA manifest for the release
A manifest lets you deploy the whole set in one operation. This one matches the running example.
<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
<types>
<members>CaseList</members>
<name>LightningComponentBundle</name>
</types>
<types>
<members>CaseListController</members>
<name>ApexClass</name>
</types>
<types>
<members>My_Support_Site1</members>
<name>ExperienceBundle</name>
</types>
<types>
<members>My Support Site</members>
<name>Network</name>
</types>
<types>
<members>My_Support_Site</members>
<name>CustomSite</name>
</types>
<version>60.0</version>
</Package>The version should match the apiVersion in your component meta files. Mixing versions is allowed, but it makes behavior harder to reason about.
Validate, then deploy
Run a validation-only deployment first. The --dry-run flag runs the full deployment checks, including Apex tests, and saves nothing.
sf project deploy start \
--manifest manifest/package.xml \
--target-org staging \
--dry-run \
--test-level RunLocalTestsIf validation passes, run the same command without --dry-run. Deployments to production require Apex test coverage, so a validated run catches failing tests before your release window.
Deploy dependencies in the same operation. ExperienceBundle references your component by name, so a bundle that arrives before the LightningComponentBundle fails. A single manifest avoids that ordering problem.
Publishing the site
After the deployment succeeds, the new components exist in the target org, and the draft site references them. Publish from Experience Builder with the Publish button, or from the CLI.
sf community publish \
--name "My Support Site" \
--target-org stagingPublishing is asynchronous. The command queues the job, and the site's owner receives an email when it finishes. For LWR sites, publishing also builds and stores a new version of the site's content, so it can take longer than a draft save. Run the CLI command in a release script, then check the live URL before you announce the release.
Publishing is also the point where a site becomes available for the first time. A site in the Inactive state, or one you created but never published, is not reachable by visitors. Activate it from Experience Workspaces under Administration, Settings.
Guest and external user access
Components can fail at runtime after a clean deployment, because deployment moves metadata but does not decide who may use it. Three settings matter most for the CaseList example:
- Apex class access. The guest user profile or an assigned permission set must list
CaseListController. Without it, the wire adapter returns an error andcases.datastays undefined. - Object and field permissions.
WITH USER_MODEenforces these, so the site user needs read access toCaseand toCaseNumber,Subject, andStatus. - Sharing. Guest users have restricted record access, and they get only what sharing rules give them.
CaseListalready shows a login prompt to guests throughisGuest, so for a logged-in-only feature, the guest profile may need no Case access at all.
Profiles are verbose and hard to merge across environments. Prefer permission sets for external users, and deploy them with the same manifest. The guest user profile is the exception, because a site has exactly one guest profile. Retrieve it from the target org before editing so you do not overwrite settings other teams changed.
Environment differences
Some values change per environment. Check these before each release:
- URL path prefix. The
Networkmetadata carries it. Two sites in one org cannot share a prefix. - Custom domains and CDN settings. These are usually configured per environment in Setup and are not part of the manifest.
- Record Ids. A
recordIdhard-coded in anExperienceBundleproperty exists in one org only. Pass such values through custom labels, custom metadata, or a record lookup instead. - Content. CMS or Salesforce-managed content that pages reference can need a separate migration. Check that content renders in the target org's builder preview before you publish.
- Member and profile assignments. Which profiles and permission sets may log into the site is set per site. Verify it after the first deployment.
A release routine
Use the same order every time:
- Retrieve the site metadata from the source org and commit it.
- Validate against the target with
--dry-runandRunLocalTests. - Deploy the manifest, including permission sets and the guest profile changes.
- Open the draft in Experience Builder and run the preview as the guest user and as a real external user.
- Publish with
sf community publish. - Wait for the completion email, then load the live URL in a private window and walk through the key pages.
Common failures
| Symptom | Likely cause | Fix |
|---|---|---|
| Deployment fails on `ExperienceBundle` | Referenced component or Apex class missing from the manifest | Add it to the same manifest |
| Component shows in builder but not on the live site | Site not published | Publish, then reload the live URL |
| Live component shows no data for guests | Guest profile lacks Apex class or object access | Update the profile, redeploy, and retest as a guest |
| Component missing from the builder palette | `isExposed` is false or the target is missing in the meta file | Fix the meta file and redeploy |
| Publish command returns an error | Site name differs from the `Network` name | Use the site label as shown by `sf community list` |
Exercise
You deployed a new version of CaseList and CaseListController to a staging org, and the component works in Experience Builder preview. Guests testing the live URL see only "No cases found" for logged-in test data, and logged-in users see an error. Name the two checks to make first.
Show answer
First, check that the site was published after the deployment, because the live site serves the last published snapshot, not the draft. Second, check that the profile or permission set for the site user lists CaseListController under Apex class access and grants read access to Case and its fields, because WITH USER_MODE and class access fail for users without them. Test the permissions in a private window as the correct user type.