back to blog
2GP in Salesforce
June 17 2023 • 10 min read

WHAT IS 2GP

If your goal is to build an app and distribute it on AppExchange, you’ll use managed packages to do both. Packaging is the container that you fill with metadata, and it holds the set of related features, customizations, and schema that make up your app.

A package can include many different metadata components, and you can package a single component, an app, or library.

To know more about second-generation managed packages check this link.

BEFORE CREATING A 2GP

Before you create a second-generation managed package, please go through this link.

Make sure that all the components in the package support 2GP packaging coverage as listed in the Metadata Coverage Report.

INSTALL AND SETUP VS CODE

If you have already installed VS Code and set up your Java Home in it, please skip this step.

If not then please follow the steps Download and Install Visual Studio Code, Setup Visual Studio Code from this Blog

RETRIEVE THE METADATA

Whether we are packaging a feature, a component or an app, all the metadata should be put together into a folder to package it.

The metadata can be retrieved from an Org in two different ways

  1. Using an unmanaged package
  2. Using the Package.xml Generator in VS Code(some metadata types are not available to retrieve using this extension)

1. USING AN UNMANAGED PACKAGE

1.1  Please go through the step How to create an unmanaged package from the Unmanaged Packages blog to create an unmanaged package and include all the metadata components that you want to package.

1.2  Check the step Create a Project from this Blog to create a project in VS Code.

1.3  Wait for a few minutes for the extensions to run and become active.

1.4  Open command palette again and search and select SFDX: Authorize an org.

screenshot 20221125 053753

1.5  Select Custom and enter the login url of the org from which you need to pull the metadata

screenshot 20221125 053832

1.6  Type an org alias and hit enter.

2gp orgalias

1.7  You will be taken to the Salesforce login page, enter your credentials and login.

1.8  Switch back to your VS Code and you will see the message Authorize an Org successfully run.

1.9  Open the terminal in VS Code using Ctrl+` and use the following command to pull the metadata from the unmanaged package into the project.

sfdx force:source:retrieve -n <YourPackageName>
sfdx force:source:retrieve -n <"Your Package Name">

1.10 A new folder will be created in your project with the package name and all the metadata will be pulled into it.

2. USING PACKAGE.XML GENERATOR IN VS CODE

2.1  Open VS Code

2.2  Open command palette, search and select SFDX: Create a project with Manifest.

2gp project with manifest

2.3  Create the project.

2.4  Authorize the org. (Check the previous step)

2.5  Before retrieving the metadata make sure all the components that you want to package support 2GP packaging Metadata Coverage Report.

2.6  Open command palette, search and select SFDX Package.xml Generator : Choose Metadata Components.

2.7  Choose all the components that you want to retrieve and click Update Package.xml.

screenshot 2023 04 21 195121

2.8  Save the file.

2.9  Right click on the screen and select SFDX: Retrieve source in manifest from the org.

2.10  All the metadata that you have chosen will be pulled into the force-app folder of your project.

CREATE THE 2GP PACKAGE

Use the following command to create the 2GP package

sfdx force:package:beta:create --name <"Package Name"> --path "<folder path where metadata resides>" --packagetype Managed

CREATE PACKAGE VERSION

A package version is a fixed snapshot of the package contents and related metadata. The package version is an installable, immutable artifact that lets you manage changes and track what’s different each time you release or deploy a specific set of changes

sfdx force:package:beta:version:create --package <"Your Package Name"> --installation-key <TestPassword> --codecoverage --wait 15
sfdx force:package:beta:version:create --package <"Your Package Name"> --installation-key-bypass --codecoverage --wait 15

You can either use an installation key or bypass it.

PROMOTE THE PACKAGE

Use the below command to promote the package.

sfdx force:package:version:promote -p <packageVersionId> -n

Note : Once the package is promoted the action cannot be rolled back.

SUBMIT FOR SECURITY REVIEW

To know the documents that are required for your solution to submit for the review, check the Required Materials for Security Review Submission | ISVforce Guide | Salesforce Developers and Security Review Submission Requirements Checklist Builder.

Login to partners.salesforce.com using your credentials and go to the publishing tab.

2gp publishing tab

Select Technologies at the top and click on Connect Technology

2gp technologies

Choose Org and connect the org which the package belongs to.

2gp rg

Now you will be able to see your package under the Solutions tab.

Click on the package name and click Edit Review.

You will be able to add Contacts, Technical Details, Upload Documentation, Provide Environments and then submit for the security review.

Once it is Approved, you will be able to add the package to the listing and publish it on AppExchange.

WRAPPING IT UP

We have covered what is a second generation managed package(2GP), how to retrieve metadata, create and promote a 2GP in order to submit it for security review.

Leave a Comment

Your email address will not be published

© 2024 Digital Biz Tech