9

How do I create a scratch org that has the same namespace as my Developer Edition org where the managed package is held?

I've followed the instructions in the "Link a Namespace to a Dev Hub Org" page to link the namespace to my Dev Hub org, but I cannot find any instructions on any of the documentation pages below for how to actually create a new scratch org that has the same namespace as my DE org.

2 Answers 2

17

In the project configuration file, specify the namespace.

{ 
"packageDirectories" : [ 
    { "path": "force-app", "default": true}
  ],
"namespace": "myns", 
"sfdcLoginUrl" : "https://login.salesforce.com", 
"sourceApiVersion": "44.0"
}

This really only alluded to in the documentation, but sfdx-project.json is the key to creating a scratch org with a namespace.

6
  • 2
    Also worth noting that the namespace has to be registered in your dev org, otherwise you'll get a cryptic error message about some kind of standard javascript name, IIRC.
    – berry120
    Sep 28, 2018 at 20:38
  • 1
    Beautiful. Worked like a charm!
    – Marty C.
    Oct 1, 2018 at 15:50
  • 1
    Thanks for clarifying. I would totally expect the namespace setting to be in the scratch org definition file, and not the project file. So confusing. Jun 9, 2019 at 19:53
  • @sfdxfox- i need to create a scratch org without namespace. Would I then just make namespace field blank?
    – Seyitbek
    Oct 22, 2019 at 16:39
  • 1
    @Seyitbek yes, use the empty string ("") to denote that there is no namespace.
    – sfdcfox
    Oct 22, 2019 at 16:59
2

Link a Namespace to a Dev Hub

You should have two developer edition orgs :

  • Packaging org : that contains the managed packages and the namespace
  • Development org :that we use to create the scratch org

Steps:

  1. Enable devhub in the development dev org

  2. Go to profile (system admin) make sure that "SalesforceDX Namespace Registry" is checked

  3. From the app launcher look for "Namespace Registries" list view

  4. Click on link namespace and authorize the Packaging org

  5. Add namespace attribute to the scratch org definition file "project-scratch-def.json" as follows:

      {
           "orgName": "..",
           "edition": "Developer",
          "features": [],
          "namespace": "your_name_space"
        ..
    }
  1. Create the scrath org

    sfdx force:org:create -s -a -f config/project-scratch-def.json -d

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.