6

These SFDX community commands are available, but on my first try just running these commands:

sfdx force:community:create --name Portal --templatename 'My Template' --urlpathprefix portal
sfdx force:community:publish --name Portal

the "create" output was:

=== Create Community Result
Your community is being created. We’re creating your community.
Run sfdx force:org:open -p _ui/networks/setup/SetupNetworksPage
to view a list of your communities,
and to confirm when this community is ready.

quickly followed by the "publish" output:

ERROR running force:community:publish: The Portal community doesn't exist.
Verify the community name and try publishing it again.

If you have a strategy for waiting until the community is created (that is better than just an arbitrary sleep) in an automated script to address this problem, please share it.

3

The Community creation process is asynchronous, and the time required varies significantly depending on what template you select.

In CumulusCI's create_community task (which calls the same endpoint as SFDX, I believe; it's the new Connect API resources introduced in Summer '19), I poll the connect/communities endpoint with a GET request to find a list of all Communities, and I just wait for the name of the Community I asked to create to appear there.

In Python, it's something like this, where sf is a simple_salesforce instance:

while True:
    community_list = sf.restful("connect/communities")["communities"]
    communities = {c["name"]: c for c in community_list}
    if target_community_name in communities:
        self.logger.info(
            "Community {} created".format(communities[target_community_name]["id"])
        )
        break

Polling based on the URL path prefix would also work fine. connect/communities returns a list of community records in the key communities. The endpoints are documented here, and particularly you want the GET resource under Community List.

You'd want to insert some kind of sleep in each loop iteration to keep the polling reasonable.

|improve this answer|||||
  • Thanks David, makes sense though disappointing that there is no direct SDFX mechanism for this. – Keith C Mar 26 at 17:45
  • we've created a couple plugins which has been a smooth process, you might think about creating your own synchronous version of the command that creates the community and then polls for it to be created ... – Ralph Callaway Mar 31 at 20:30
  • Thanks @RalphCallaway, that is a maybe. Presently we've put most of our effort in this direction github.com/claimvantage/sfdx-jenkins-shared-library (though perhaps we should move to CumulusCI instead). – Keith C 2 days ago

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.