Second-generation managed packaging (2GP) ushers in a new way for AppExchange partners to develop, distribute, and manage their apps and metadata.

You can use 2GP to organize your source, build small modular packages, integrate with your version control system, and better utilize your custom Apex code. With version control being the source of truth, there are no packaging or patch orgs. 

You can execute all packaging operations via Salesforce CLI, or automate them using scripts. Submit second-generation managed packages for security review, and list them on AppExchange.

Create Second-Generation Managed Packages

Verify the following before 2GP Packages

  1. Enable Dev Hub in Your Org
  2. Enable Second-Generation Managed Packaging
  3. Install CLI
  4. Create and Register Your Namespace

The maximum number of 2GP package versions that you can create from a Dev Hub per day is the same as your daily scratch org allocation. To request a limit increase, contact Salesforce Customer Support.

Important Points related to 2GP Packages

  • Your version control system is the source of truth (source-driven system) for the metadata in your package.

    And unlike 1GP, 2GP doesn’t use packaging or patch orgs.

  • The Dev Hub owns the package, but the Dev Hub doesn’t contain the packaged metadata. We recommend that you enable Dev Hub in your Partner Business Org (PBO).

  • A Dev Hub can own one or more packages.

  • The namespace of a managed package is created in a namespace org and linked to the Dev Hub.

  • A namespace is linked with a 2GP when you run the force:package:createSalesforce CLI command. And you must specify the namespace in the sfdx-project.json file.

  • Multiple packages can use the same namespace.

  • Multiple packages sharing the same namespace can share code using public Apex classes and methods with @namespaceAccessible annotation.

  • All packaging operations can be automated using Salesforce CLI.

  • Package versioning supports branches.
  • Patch versions are created using Salesforce CLI. The version control system is the source of truth, and there are no patch orgs.

Best Practices for 2GP Packages

Follow these best practices when working with second-generation managed packages.

  • We recommend that you work with only one Dev Hub, and enable Dev Hub in your partner business org.
  • The Dev Hub org against which you run the force:package:create command becomes the owner of the package. If the Dev Hub org associated with a package expires or is deleted, its packages no longer work.
  • Include the --tag option when you use the package:version:create and package:version:update commands. This option helps you keep your version control system tags in sync with specific package versions.
  • Create user-friendly aliases for packaging IDs, and include those aliases in your Salesforce DX project file and when running CLI packaging commands.


Reference Links:



This is Open Community Blogger Platform and community forum of SFDC professionals interested to share their experiences, ideas, and thoughts or any content invaluable to help others in this domain.