Have you heard about 2nd generation in salesforce? Have you taken advantage of the benefits of second-generation packages (also known as 2GPs) for your unused apps, however? On the off chance that you aren’t, you ought to be. In this blog, we’ll cover benefits, points of interest, and why creating apps with these packages is the clear alternative.
A package is a bundle of components that are AppExchange partners use to utilize and distribute their app on the app exchange. This bundle of components consists of metadata, features, enhancements, customizations, etc.
The second-generation (2GP) package is intended for AppExchange partners to distribute, publish, and manage their apps on App exchange.
Let’s discuss about what are Second generation packages in detail.
What are 2GP?
2GP can be used to build your source, organize small modular packages, utilize apex custom code in a better way and integrate with our version control system.
With Version control being the source of truth, there is no need for a packaging or a patch org.
We can execute all packaging operations via salesforce CLI or automate them using Scripts.
We can also submit these packages for security review and publish them on app exchange.
Here is a quick difference between 1GP and 2GP packages:
Pre-requisites for creating 2GP packages:
- Enable dev hub in your org.
- Enable second-generation managed packages.
- Install Salesforce CLI.
- Create and Register your Namespace.
Note: Developers who use 2GP packages need the correct permission set in the dev hub org. They need either the system administrator profile or the Create or update second generation managed packages permission.
For points 1 and 2, here is the screenshot:
To better understand how the 2GP Packages work, here is a quick depiction of its lifecycle and components:
Image Source = Google | Image By – Salesforce
Steps to Create 2nd Generation managed packages:
- Create a DX project.
- Authorize the Dev Hub org, and create a scratch org.
- Create a scratch org and develop the app you want to package.
- Verify that all package components are in the project directory where you want to create a package.
- In the sfdx-project.json file, specify a namespace using the namespace attribute. For example: “namespace”: “hotel-mgr”
- From the Salesforce DX project directory, create the package.
- Review your sfdx-project.json file.
- Create a package version.
- Install and test the package version in a scratch org. For this use a different scratch org from the one you have used above.
- After the package is installed, open the scratch org to view the package.
- When you’re ready to release, use
- If the command is successful, a confirmation message appears.
This is very usefull if we want to test our package in scratch org before submitting it in AppExchange for validation