How to deploy a Salesforce Community/Experience Site with SFDX (plus GitHub repo)
Well, I just went to hell and back trying to figure out how to deploy Communities (Experiences) with sfdx.
Salesforce does provide some documentation on how to use the Metadata API to deploy communities, but it doesn't cover all the details.
Weird metadata
The first thing to be aware of is that the metadata of a community is all over the place. At the time of this writing, it's represented by 3 main objects: Network, CustomSite, and ExperienceBundle
The gist is that Network
and CustomSite
represent the settings/configuration of the community while ExperienceBundle
is the actual community, its pages, navigation, routes, etc.
If you are completely new to the metadata structure of communities, I highly recommend this amazing article by Rajat Sharma, which goes into great detail about this structure.
This article (the one you are reading right now) is more concerned about the deployment rather than the structure.
Dependency Hell
Deploying these 3 objects is easy. The problem is that a community is not just a community, it's a community that references a ton of other metadata in the org.
Based on my testing, a community can reference:
- Custom fields
- LWCs and Auras
- Visualforce pages
- Permission Sets
- Profiles
- Apex Classes
- Email Templates
That's just the first level of dependency. These metadata types can then reference other metadata types. For example, Apex Classes can reference other visualforce pages
PageReference page = System.Page.CommunitiesSelfRegConfirm;
page.setRedirect(true);
return page;
And those pages can then reference other apex classes
<apex:page id="communitiesSelfRegConfirmPage" controller="CommunitiesSelfRegConfirmController" showHeader="true" cache="false" title="{!$Label.site.registration_confirmation}" >
The same is true with profiles and permission sets, and LWC's.
So the real challenge is remembering to add all the related metadata that makes up the community.
To figure out the dependencies, I recommend using Salto's free tier or HappySoup.io
A sample git repo ready-to-go
Of course, I didn't go to hell and back just to let you know I made it back. I ended up putting an sfdx project in GitHub that contains a fully deployable community, along with all its related metadata. Here you go:
You missed the best part 😔. Join the community of 70+ paid subscribers who are embracing a software engineering mindset and benefiting from this exclusive content. Don't be left behind—stand out from the crowd!