Sub topic 15
Deploying components and publishing the site
This chapter assumes you can run Salesforce CLI commands in a Salesforce DX project and that you already have a component exposed to Experience Builder. It covers how to move components and site configuration between orgs, and how to make the changes visible to visitors.
Deploy and publish are separate steps
A deployment puts metadata into an org. Publishing copies the site's saved configuration to the live URL that visitors use. After a deployment, the Builder shows your component, but the live site doesn't change until you publish.
What to deploy
A site that uses custom components depends on several metadata types:
| Metadata type | Contains |
|---|---|
| LightningComponentBundle | Your component files |
| ApexClass | Controllers such as `CaseListController` |
| Network | Site settings, such as the member profiles |
| CustomSite | The site's underlying Salesforce Site record |
| ExperienceBundle | Pages and layout of an Aura site, or of an LWR site stored in this format |
| DigitalExperienceBundle | Pages and layout of LWR sites that use the Digital Experience format |
| Profile | Guest user access to Apex classes and objects |
If you deploy only the component, existing pages keep working. A new page that uses the component also needs the site metadata.
Deploy with the CLI
Use a manifest so the deployment is repeatable. This package.xml lists the types for an Aura site. MySite stands for your site's name.
<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
<types>
<members>caseList</members>
<members>caseLink</members>
<name>LightningComponentBundle</name>
</types>
<types>
<members>CaseListController</members>
<name>ApexClass</name>
</types>
<types>
<members>MySite1</members>
<name>ExperienceBundle</name>
</types>
<types>
<members>MySite</members>
<name>Network</name>
</types>
<types>
<members>MySite</members>
<name>CustomSite</name>
</types>
<version>60.0</version>
</Package>Deploy it, then publish:
sf project deploy start --manifest manifest/package.xml --target-org myTargetOrg
sf community publish --name "MySite" --target-org myTargetOrgThe --name value is the site's name as shown in Setup, not its URL path.
Check access after deploying
Most failed releases come from access settings that were not deployed. Check these in the target org:
- The guest user profile can read the objects and fields the component queries.
- The guest profile and member profiles or permission sets have access to each Apex class.
- Sharing rules and guest sharing rules match what you tested in the source org.
Publishing in the Builder
You can also publish in Experience Builder with the Publish button, or from Setup > All Sites. Keep these points in mind:
- A site must be activated before it is reachable by visitors. Publishing an inactive site does not activate it.
- Publishing starts an asynchronous job, and the org emails an administrator when it finishes.
- Each publish replaces the live version. You can't publish a single page.
- A sandbox publish updates the sandbox URL only. Production needs its own deployment and publish.
Common errors
- Component missing in the Builder: the meta file lacks
isExposedset totrue, or the target is wrong for the site type. - Data shows in preview but not live: you changed the site but did not publish it.
- "Insufficient privileges" for guests: Apex class access was not deployed with the guest profile.
Exercise
You deployed a new version of caseList to production with sf project deploy start. Visitors still see the old component. What is the most likely cause, and which command fixes it?
Show answer
The site was not published. Deployment updates the org, but the live site only changes after publishing. Run sf community publish --name "MySite" --target-org myTargetOrg, or use Publish in Experience Builder.