
Andrew Hanna

Andrew Hanna

TL;DR: Second-generation packaging (2GP) is Salesforce's modern, source-driven way to build and distribute managed and unlocked packages from version control instead of a packaging org. It replaces first-generation packaging (1GP) with modular packages, flexible namespaces, explicit dependencies, and a Salesforce CLI workflow. Salesforce now recommends 2GP for all new managed package development.
A 2GP package is a container for the metadata, code, and schema you distribute as an app - to AppExchange customers (managed) or across your own org estate (unlocked). The defining idea is that the package is built from source in Git, not from a stateful packaging org. Salesforce is explicit that managed 2GP "isn't merely version 2.0" of 1GP; it is a different, automation-friendly development model, and it is the recommended path for all new packages.
The short version: 1GP lives in a packaging org, 2GP lives in your repository. That single change unlocks the rest:
sfdx-project.json, not discovered at install time.
Both are second-generation packages built the same way. The choice is about audience:
You need a Dev Hub org with Unlocked Packages and Second-Generation Managed Packages enabled, and the Create and Update Second-Generation Packages permission. Then:
sf package create --name MyApp --package-type Managed --path force-app
--target-dev-hub DevHub
sf package version create --package MyApp --installation-key test1234
--code-coverage --wait 10 --target-dev-hub DevHub
sf package install --package 04t... --wait 10
sf package version promote --package [email protected] --target-dev-hub DevHub
A promoted managed version is the one you submit to AppExchange security review before customers can install it.
Because the whole flow is CLI-first, it slots into a DevOps pipeline - the same place tools like Copado, Gearset, Salto, AutoRABIT, Flosum or Blue Canvas orchestrate version control and testing. For more build-and-release playbooks, see our SF Guides.
Is 2GP replacing 1GP?
Salesforce recommends 2GP for all new managed packages, though existing 1GP packages still work and can be migrated.
Do I need a Dev Hub for 2GP?
Yes. Enable Dev Hub and second-generation packaging, and grant the create/update packages permission before you start.
Can two 2GP packages share a namespace?
Yes. Several managed 2GP packages can use one namespace, but each package binds to a single namespace that cannot change after creation.
What is the difference between managed and unlocked packages?
Managed 2GP is for AppExchange distribution with IP protection; unlocked packages organize your own org's metadata into versioned, deployable units.
Commitment free!