Think. Build. Salesforce Solutions.

Salesforce Consulting Services across Salesforce Clouds & Across App Lifecycles

Blog

Second Generation Packages in Salesforce

By |2022-04-05T05:46:41+00:00April 4th, 2022|

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:

Second Generation Packages in Salesforce

Pre-requisites for creating 2GP packages:

  1. Enable dev hub in your org.
  2. Enable second-generation managed packages.
  3. Install Salesforce CLI.
  4. 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:

Second Generation Packages in Salesforce

To better understand how the 2GP Packages work, here is a quick depiction of its lifecycle and components:

second generation packages salesforce-min                                      Image Source = Google | Image By – Salesforce

Steps to Create 2nd Generation managed packages:

  1. Create a DX project.
    2gp package salesforce
  2. Authorize the Dev Hub org, and create a scratch org.
    2gp package salesforce
  3. Create a scratch org and develop the app you want to package.
    2gp package salesforce
  4. Verify that all package components are in the project directory where you want to create a package.
  5. In the sfdx-project.json file, specify a namespace using the namespace attribute. For example: “namespace”: “hotel-mgr”
  6. From the Salesforce DX project directory, create the package.
    2gp package salesforce
  7. Review your sfdx-project.json file.
    2gp package salesforce
  8. Create a package version.
    2gp package salesforce
  9. Install and test the package version in a scratch org. For this use a different scratch org from the one you have used above.
    2gp package salesforce
  10. After the package is installed, open the scratch org to view the package.
    2gp package salesforce
  11. When you’re ready to release, use
    2gp package salesforce
  12. If the command is successful, a confirmation message appears.
    2gp package salesforce

One Comment

  1. Firas January 31, 2023 at 9:57 pm - Reply

    This is very usefull if we want to test our package in scratch org before submitting it in AppExchange for validation

Leave A Comment