When building Apex code that needs to identify specific Experience Cloud sites (formerly known as Communities), you can retrieve the unique Site ID for each site programmatically. The ConnectApi.Communities.getCommunities() method returns a list of all Experience Cloud sites the running user has access to, including their IDs, names, and URLs.
Retrieving Experience Cloud Site IDs programmatically is useful in the following scenarios:
Run the following statement in the Developer Console's Execute Anonymous window, or include it in a debug log for review. The statement calls the getCommunities() method from the ConnectApi.Communities class, which returns a CommunityPage object containing a list of Community objects.
System.debug('##### ' + ConnectApi.Communities.getCommunities());
After running this statement, open the debug log and search for #####. The output includes a list of ConnectApi.Community objects. Each object contains the following properties:
You can use the id value in subsequent Apex logic to reference or filter by a specific Experience Cloud site.
000386512

We use three kinds of cookies on our websites: required, functional, and advertising. You can choose whether functional and advertising cookies apply. Click on the different cookie categories to find out more about each category and to change the default settings.
Privacy Statement
Required cookies are necessary for basic website functionality. Some examples include: session cookies needed to transmit the website, authentication cookies, and security cookies.
Functional cookies enhance functions, performance, and services on the website. Some examples include: cookies used to analyze site traffic, cookies used for market research, and cookies used to display advertising that is not directed to a particular individual.
Advertising cookies track activity across websites in order to understand a viewer’s interests, and direct them specific marketing. Some examples include: cookies used for remarketing, or interest-based advertising.