Salesforce DX – How to Deploy externalSharingModel Setting

Background: I have a problem where if I try to deploy my entire set of metadata to a newly created scratch org, it fails because the sharing settings of certain objects are incorrect by default, causing errors regarding AssetShare and OrderShare records not being available with the current sharing setup.

I can solve these issues by manually setting the sharing to the correct values, but I want to automate the entire process. I'm trying to deploy only the Asset and Order object metadata file first, containing only the sharing setting, like so:

<?xml version="1.0" encoding="UTF-8"?>
<CustomObject xmlns="http://soap.sforce.com/2006/04/metadata">    
    <sharingModel>Read</sharingModel>
    <externalSharingModel>Private</externalSharingModel>
</CustomObject>

I want to set both regular sharing and external sharing, which I can do manually without any issues, but when I try to deploy I immediately get the response that the deploy Can't specify an external sharing model for Order (same thing for Asset)

I tried deploying the metadata without the externalsharing, but besides locking changes to the sharing for 15+ minutes, that only resulted in an email saying that changing the sharing was unsuccessful.

EDIT: Likely this is precisely because external sharing isn't being updated alongside it, because if I try to only edit the internal sharing and leave external as-is, I get an error in the UI saying The default external access must be more restrictive or equal to the default internal access.

Best Answer

In short: Order Sharing Settings have to be set via the UI.

Solution: try to build selenium automation for this, maybe have a start here.

So what makes me say this?

First of all let's have a look at the example scratch org setup I made: {

"orgName": "testorg",
"country": "US",
"language": "en-US",
"edition": "Developer",
"features": ["ExternalSharing"],
"settings": {
}

}

Then I tried deploying your specified object files, which were resulting in the stuck sharing calculation, in two different scratch orgs. On the other hand, just as you said already, manual setting works totally fine.

The other funny thing is, that if you try that with any other object than order, deploying works fine as well.

Well, it's not that much of information, but it is a confirmation that this is just the way it works and there is not much we could do about, except building the workaround with ui automation.

Related Topic