2

I would like to build 2GP package to refer PackageSubscriber object. This object is available only in DevHub orgs. I don't want to develop this package on DevHub org, but rather develop it in scratch org and then install the built package to use in DevHub.

The problem is that when I try to include DevHub setting in the scratch org definition,

{
    "orgName": "Enterprise",
    "edition": "Enterprise",
    "features": [],
    "settings": {
        "mobileSettings": {
            "enableS1EncryptedStoragePref2": false
        },
        "devHubSettings": {
            "enablePackaging2" : true, "enableScratchOrgManagementPref": true
        }
    }
}

by a command

sfdx force:org:create -s -d 30 -a manenter$(( RANDOM % 1000)) -f config/manual.json 

it fails with the following error

ERROR running force:org:create: A scratch org was created with username [email protected], but the settings failed to deploy

I don't understand, why it fails?

If I manually create a file DevHub.settings-meta.xml with the following content

<?xml version="1.0" encoding="UTF-8"?>
<DevHubSettings xmlns="http://soap.sforce.com/2006/04/metadata">
    <enablePackaging2>true</enablePackaging2>
    <enableScratchOrgManagementPref>true</enableScratchOrgManagementPref>
    <enableShapeExportPref>false</enableShapeExportPref>
</DevHubSettings>

and try to deploy it using SFDX command

sfdx force:source:deploy -m Settings:DevHub

this also fails without any descriptive error message

*** Deploying v53.0 metadata with SOAP API v54.0 connection ***
Deploy ID: 0Af1900001RMQsrCAH
DEPLOY PROGRESS | ████████████████████████████████████████ | 1/1 Components

=== Component Failures [1]
Type   Name    Problem
─────  ──────  ──────────────────────────────
Error  DevHub  enableScratchOrgManagementPref

ERROR running force:source:deploy:  Deploy failed.

Ok, let's assume that we cannot have this settings enabled, and update the DevHub.settings-meta.xml file to have enableScratchOrgManagementPref set to false

<?xml version="1.0" encoding="UTF-8"?>
<DevHubSettings xmlns="http://soap.sforce.com/2006/04/metadata">
    <enablePackaging2>true</enablePackaging2>
    <enableScratchOrgManagementPref>false</enableScratchOrgManagementPref>
    <enableShapeExportPref>false</enableShapeExportPref>
</DevHubSettings>

and try again, and it fails again

sfdx force:source:deploy -m Settings:DevHub
*** Deploying v53.0 metadata with SOAP API v54.0 connection ***
Deploy ID: 0Af1900001RMSh3CAH
DEPLOY PROGRESS | ████████████████████████████████████████ | 1/1 Components

=== Component Failures [1]
Type   Name    Problem
─────  ──────  ────────────────
Error  DevHub  enablePackaging2

I am thinking now about using an org shape and tried to create an org shape, but when I try to access the list of org shapes, I see another error

sfdx force:org:shape:list      
ERROR running force:org:shape:list:  Error authenticating with the refresh token due to: expired access/refresh token

Update: even if I create a scratch org using Org Shape from Dev Hub, it doesn't help to bring PackageSubscriber there

1 Answer 1

1

I have opened a case with Salesforce support and this is the response per Case #42999427.

It is possible to specify in scratch org settings file Dev Hub settings with Packaging2 and ScratchOrgManagement features enabled like following

"settings": {
"devHubSettings": {
"enablePackaging2" : true, "enableScratchOrgManagementPref": true
}
}

however, when scratch org is created, such settings will fail to deploy since Dev Hub features are not available on Sandboxes and Scratch Orgs.

No other means (no Feature parameters in scratch org definition file) neither org shapes will not help since Dev Hub features are totally not available on Sandboxes and Scratch Orgs.

There is no internal hack or workaround to this limitation, even Salesforce Labs team developed their package on real production data on their dev hubs and didn't mock in any way Package Subscribers data for the manual testing

You must log in to answer this question.

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