0

Related to System.runAs for CspLitePortal Profile Users recently started returning no rows, I am now wondering how to automate the setting of the external sharing model for some SObjects contained in managed packages that we automatically install in our CI scratch org.

My first thought was to use:

sfdx force:source:deploy --sourcepath config-components/externalSharingModel

to deploy just those flags for the relevant SObjects:

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

but multiple other attributes seem to be required.

Is there a simple way to set the external sharing model values in a scratch org programmatically?

(All I can think of is read/modify/write via e.g. the apex-mdapi.)

1 Answer 1

1

I've taken the simple approach here of establishing what the minimum CustomObject definition that will deploy is and it is typically:

<?xml version="1.0" encoding="UTF-8"?>
<CustomObject xmlns="http://soap.sforce.com/2006/04/metadata">
    <deploymentStatus>Deployed</deploymentStatus>   
    <externalSharingModel>ReadWrite</externalSharingModel>
    <label>Invoice</label>
    <nameField>
        <label>Invoice Number</label>
        <type>Text</type>
    </nameField>
    <pluralLabel>Invoices</pluralLabel>
    <sharingModel>ReadWrite</sharingModel>
</CustomObject>

with the build deploying these via a single:

sfdx force:source:deploy --sourcepath config-components/externalSharingModel

Tedious to create the files but only needs doing once.

3
  • Keith, just wondering - was this related to CustomObjects that are part of the managed package itself and is that package deployed/pushed to or installed on the scratch org?
    – Phil W
    Jul 22, 2020 at 10:45
  • Hi @PhilW, This was to modify the sharing model of an object in one of our installed managed packages to suite what another managed package needed. Also prompted by the change (last year) for more explicit definition of the sharing model for the "external" case.
    – Keith C
    Jul 22, 2020 at 11:40
  • Thanks. So just to ensure I understand fully, you have package A and package B. Package A provides object A1 which package B uses. Package A sets sharing as Private for A1. Package B needs sharing to be ReadWrite. You installed A on the scratch org, pushed some metadata to change the sharing (using minimal custom object meta XMLs) then installed B, yes?
    – Phil W
    Jul 22, 2020 at 12:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .