I am trying to migrate metadata from a Partner Developer org to a Partner Developer scratch org for use with second-gen packaging.

I have downloaded the 1GP package, converted the metadata, and now I am doing a source push.

But one of the errors I am getting is:

Error myApp\main\default\connectedApps\MyApp.connectedApp-meta.xml The consumer key is already taken.

The simple fix to this is to remove the ConnectedApp, but before I do that, I want to confirm that my assumption was wrong about ConnnectedApp's.

I thought I was meant to ship a ConnectedApp with my managed package, so there was a common Consumer Key and Consumer Secret for that given package.

But based on this error, I am getting the impression this would not be possible.

  1. As an ISV providing App's on the AppExchange, should they be shipped with a common ConnectedApp?
  2. Or, should the ConnectedApp be created as part of the installation/setup process?
  • Mostly that error comes when you try to install connected app again. Related to app-exchange, I don't have much of expirience but if it just for authorization and solely technical purpose you can keep a common connected app, but if subscriber org's admin need its control, then its best to ship it with package.
    – Ysr Shk
    Nov 1, 2020 at 12:29

1 Answer 1


The best practice is to package up your connected app along with the other components in 2GP.

Now the way you package up the Connected App in 2GP is different, I will go down the steps here,

  1. Create a 1GP Managed package in your org where you have the namespace. This package can include only the Connected App. The package needs to be Managed and Released.

  2. Note down the developer name of the Connected app <connected app developer name> and the namespace namespace of your org where you have a 2GP package.

  3. Create a folder named connectedApps in the source directory.

  4. Create a file in the folder named connectedApps with the naming convention <connected app developer name>.connectedApp-meta.xml

  5. Make sure the contents of the file as below

     <?xml version="1.0" encoding="UTF-8"?>
     <ConnectedApp xmlns="http://soap.sforce.com/2006/04/metadata">
       <developerName><namespace>__<connected app developer name></developerName>
       <label><Connected App Label></label>
  6. Create package and package versions.

The above is also documented here but it is not clear so I had to hands-on dig in. I will reach the team who has it documented to make sure this is correct.

Also make sure to follow the below note carefully

When you add a connected app to a 1GP package, and upload the package, the version number of the connected app is auto incremented. For example, when version 4.0 of a connected app is added to a 1GP package, the package version increments the version number of the connected app from 4.0 to 5.0. When creating the source file for your 2GP package, specify the version number of the connected app before it was uploaded into a 1GP package, in this case, 4.0.

For Scratch Orgs

Create a 1GP package with a different namespace for testing it. Install the 1GP package in your scratch orgs to use the connected app, you can install using the below command. You need the package Id and use it in the below command.

sfdx force:package:install --package "04t...." 
  • Why does a Connected App have to get added to 2GP via a 1GP? It feels unnecessarily complex? why can't I just create it in my scratch org, pull it to local and then make the managd package?
    – Robs
    Nov 3, 2020 at 22:30
  • 1
    Because the consumer key used has to unique per org per connected app! That's by very old design which will require significant factoring and rework without disturbing other connected apps data! Hopefully in future it is simplified! Nov 3, 2020 at 22:34
  • 1
    Correct! Also it will help in future when Salesforce will give you a way to turn your 1GP to 2GP packages automatically! Nov 3, 2020 at 22:36
  • 1
    "in future when Salesforce will give you a way to turn your 1GP to 2GP packages automatically!" ... ah that would be nice... roll on the future!
    – Robs
    Nov 3, 2020 at 22:40
  • 1
    callback URLs can be added in new lines. You can have multiple callbacks in the connected app. Yes release a new package and install the version in scratch orgs. Nov 3, 2020 at 22:49

You must log in to answer this question.

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