Second-Generation Managed Packages (2GP)
A package is a mechanism by which AppExchange partners distribute their apps to their customers, we can assume it as a container having metadata. Salesforce uses 2 ways to package their data: First-Generation Packaging(1GP) and Second-Generation Packaging(2GP).
You can utilize 2GP to sort out your source, construct little measured bundles, incorporate with your adaptation control framework and utilize the Apex code. All bundling activities can be computerized utilizing Salesforce CLI.
Advantages of 2GP:
1) 2GP supports branching of development: 1GP encourages linear development, with linear development you can’t make changes that don’t merge with your base code before you’re ready for it to. Branching offers engineers greater dexterity in their improvement of new highlights.
2) Namespace: While in 1GP Namespace was tied to a specific package, in 2GP Namespace can be used for every package you develop.
3) Modular: 2GP allows you to decompose apps into separate modules. Smaller functional modules are easier to develop and debug.
4) Source driven system: In 1GP source of truth resides within the 1GP Packaging org whereas in 2GP version control system is the source of truth for the application.
5) Patch versioning: It is done using Salesforce CLI, version control is the source of truth and hence there are no patch orgs like it used to be in 1GP.
Despite these differences, there are certain similarities in 2GP and 1GP, the core concept of associating metadata with a package. Both allow creation of package and patch versions that can be installed and uninstalled in orgs.
Things to remember before creating a 2GP
1) Enable the Dev Hub features in your Org, this is used to manage the second generation packages and use the Einstein features. Dev Hub feature is available in developer, enterprise performance and unlimited editions.
2) From Dev Hub we can enable unlocked Packages and 2GP
3) Installing the Salesforce CLI
4) Create and register Namespace
1) Single Namespace: Within a single global namespace we can create as many 2GP packages.
2) Automate everything
3) Use the full power of the tools available to you.
4) Work with only one DevHub, as the DevHub org where force:package:create command is run becomes the owner of the package.