Sub topic 17
Moving an Existing 1GP Package to 2GP
This chapter assumes you have read the chapters on the Dev Hub, namespace linking, and package versions. You should also know the first-generation (1GP) managed package workflow, where you build uploads in a packaging org.
Why convert instead of rebuilding
If your app is already on AppExchange as a 1GP managed package, subscribers have it installed. You can't ask them to uninstall it and install a new 2GP package. Salesforce provides a conversion that creates a 2GP package version from a released 1GP version. Subscribers upgrade to it in place, and their data and configuration are kept.
Check eligibility first
- The 1GP package must be a managed package. Unmanaged and unlocked packages can't be converted this way.
- The packaging org that owns the 1GP package must have its namespace linked to your Dev Hub.
- You need the 1GP package ID, which starts with
033. Find it in the packaging org's Package Manager. - Your
sfdx-project.jsonmust list a package directory and use the same namespace as the 1GP package.
Run the conversion
sf package convert \
--package 033XXXXXXXXXXXXXXX \
--installation-key-bypass \
--wait 20 \
--target-dev-hub devhubReplace 033XXXXXXXXXXXXXXX with your 1GP package ID. The command creates a 2GP package record in the Dev Hub under the same namespace. It then builds a converted package version from the 1GP metadata. The version is a beta, like any new 2GP version. Check the result with this command:
sf package version list --target-dev-hub devhubValidate, promote, release
Treat the converted version like any other 2GP version.
- Install the beta in a scratch org or sandbox that already has the 1GP version. Confirm that the upgrade succeeds.
- Check that existing data, page layouts, and Apex behavior are unchanged.
- Promote the version with
sf package version promote. - Give subscribers the released version through your normal install or push upgrade process.
Common pitfalls
- Unlinked namespace. Conversion fails if the Dev Hub doesn't own the namespace link. Fix the link before anything else.
- Package IDs change. The converted 2GP package has a new
0HoID, so update scripts, CI jobs, and aliases that referenced the old package. - Stopping 1GP uploads. Plan to release future versions from 2GP only. Keeping two build paths for one namespace causes confusion about which version is current.
- Skipping the upgrade test. A conversion can succeed even when an upgrade in a real subscriber org would reveal problems. Test against an org that holds real 1GP installs.
Exercise
Your 1GP managed package is live on AppExchange. What is the first requirement to check before running sf package convert, and what do you test before promoting the converted version?
Show answer
Check that the 1GP package's namespace is linked to your Dev Hub, and that you have the 033 package ID. Before promoting, install the beta over an org that has the 1GP version installed and confirm the upgrade succeeds and existing data and behavior are intact.