Package an External Client App That Isn't on a Dev Hub Org

To package an external client app that wasn't created on a Dev Hub org, use a namespace to connect the org to a Dev Hub org.

Required Editions

Available in: Lightning Experience
Available in: Professional, Performance, Unlimited, and Developer Editions
User Permissions Needed
To create an external client app Create, edit, and delete External Client Apps

Create an External Client App and Configure the Source Org

  1. Create a packageable external client app.
    1. Create an external client app
    2. For Distribution State, select Packaged.
  2. Configure a namespace for the org.
  3. To authenticate the org, select a name for your org and run this command with Salesforce CLI.
    sf org login web -a <org name>
  4. Run this command to pull the metadata into your local Salesforce DX project.
    sf project retrieve start --manifest package.xml -o <org name>

Configure the Dev Hub Org

  1. Enable the Dev Hub org.
    1. From Setup, in the Quick Find box, enter Dev Hub and select Dev Hub.
    2. To enable Dev Hub, click Enable.

      After you enable Dev Hub, you can’t disable it.

    3. Enable Unlocked Packages/Second-Generation Managed Packages.
  2. Link the namespace from the org with your external client app in the Namespace Registry of the Dev Hub org.
  3. Authenticate the Dev Hub with Salesforce CLI.
    sf org login web --set-default-dev-hub

Create a Second-Generation Managed Package

  1. Update the project-scratch-def.json for the Salesforce DX project to allow external client app packaging from a different org. Add this setting.
    {
      "settings": {
        "externalClientAppSettings": {
          "enablePackageEcaOauthFromDevOrg": true
        }
      }
    }
    

    If you don't add this setting, you get a package version creation error. The error message says you can't create external client apps in ephemeral orgs.

  2. Create the package.
    sf package create --name "testpkg" --package-type Managed --path "force-app"
  3. Create the package version.
    sf package version create --package "testpkg" --installation-key test1234 -f config/project-scratch-def.json -w 15