- Create a Connected App in Salesforce instance where we maintain namespace.
- Create a first-generation managed package (1GP) and add the connected app. It’s fine if the connected app is the only component in the package. Always use the same namespace as the 2GP package for the 1GP package.
- Take note of the version number of the connected app; this number is needed later.
- Upload the 1GP Package to create a package version.
- Promote the 1GP version to the released state.
- Promoting the 1GP version allows the connected app to be included in a second-generation managed package. We don’t need to install the 1GP version into an org.
- Now in our source code navigate to folder "connectedApps" where we are trying to generate 2GP Package
and the body of the XML file should be as shown below.
<label>A Connected App</label>
Now generate a 2GP package and promote. Then the connected app is automatically added to your 2GP Package.
The version specified in the source file is the version number of the connected app. Use decimal formatting when specifying the version number. The version number must match the version number of the connected app before it was added to the 1GP managed package.