[SalesForce] “ERROR: entity type cannot be inserted: Second Generation Package.” when trying to create Second Generation Package

I am attempting to create a Second Generation package using the Salesforce CLI. I have a Dev Hub organization connected in which Second Generation packages are enabled. I run the following command to create a package…

sfdx force:package2:create --name Promoter_io

…and receive the following output on the command line:

ERROR: entity type cannot be inserted: Second Generation Package.

Here are my configuration files for the project:

package.json:

{
    "name": "Promoter.io V1.8.1",
    "version": "1.8.1",
    "scripts": {
        "start": "sfdx force:org:open"
    }
}

sfdx-project.json:

{
  "packageDirectories": [
    {
      "path": "force-app",
      "default": true, 
      "id": "",
      "versionName": "v 1.8.1",
      "versionDescription": "Promoter.io 1.8.1",
      "versionNumber": "1.8.1.NEXT",
      "ancestorId": ""
    }
  ],
  "namespace" : "promoter",
  "sfdcLoginUrl": "https://login.salesforce.com",
  "sourceApiVersion": "41.0"
}

Any information on how I can resolve or debug this error would be helpful.

Best Answer

When you enable the org-wide setting in the Dev Hub menu, the only user profile that will have the permission enabled is the default Sys Admin profile. If you use another profile in production, you need to grant the "Create and Update Second-Generation Packages" permission for the profile being used or otherwise add the permission to yourself.

I was stuck myself, but found this article to help: https://developer.salesforce.com/docs/atlas.en-us.sfdx_dev.meta/sfdx_dev/sfdx_dev_dev2gp_before.htm

You'll likely also want to give yourself/profile the "Promote a package version to released" permission.

Related Topic