what are packages ?
1.Package is a container of meta data.
2.It contains a set of related features,customizations and schema.
3.Use packages to move metadata from one Salesforce org to another.
4.As you add, remove or change the packaged metadata,you create many package versions.
5.Each package version has a version number, and subscribers can install a new package version into their org through a package upgrade.
6.you can distribute the package to your customers via AppExchange also.
Pre-requisites for 2GP Package :
1.Enable Dev Hub in your Org.
2.Enable Second-Generation Managed Packaging.
3.Install Salesforce CLI.
4.Create and Register your Namespace.
5.Assign the required permissions to the Developers-
Developers need either the System Administrator profile or
the Create and Update Second-Generation Packages permission in Dev Hub Org.
Dev Hub Org :
-> As owner of all Second-generation managed packages.
-> To link your namespaces.
-> To authorize and run your force:package commands.
Namespace Org :
-> The primary purpose of the namespace org is to acquire a package namespace.
-> After you create a namespace org and specify the namespace in it, link the namespace org to the Dev Hub Org.
Other Orgs :
-> you can create scratch orgs on the fly to use while testing your packages.
-> The target or installation org is where you install the package.
Create a package :
=================
Create Package :
sfdx force:package:create --name DreamDemo --path source-folder --packagetype Managed
Package Version Creation :
sfdx force:package:version:create --package "DreamDemo" -- installationkey test1234 --wait 10 --codecoverage
Promot the Package :
sfdx force:package:version:promote -package "DreamDemo@0.1.0-1"
Package Ancestors :
==================
-> Only package versions that have been promoted to managed released state can be listed as an ancestor.
-> When we define an ancestor for the packages they inherits the manageability rules of the specified ancestor package.
Note :
Specify the package ancestor in the sfdx-project.json file using either the ancestorVersion or ancestorId attribute. Use the ancestor that’s the immediate parent of the version you’re creating.
"packageDirectories": [
{
"path": "util",
"package": "Expense Manager - Util",
"versionNumber": "4.7.0.NEXT",
"ancestorVersion": "4.6.0.1"
}
]
"packageDirectories": [
{
"path": "util",
"package": "Expense Manager - Util",
"versionNumber": "4.7.0.NEXT",
"ancestorId": "04tB0000000cWwIAE"
}
]
"packageDirectories": [
{
"path": "util",
"package": "Expense Manager - Util",
"versionNumber": "4.7.0.NEXT",
"ancestorId": "expense-manager@4.6.0.1"
}
]
Best Practices :
1.Work with only one Dev Hub, and enable Dev Hub in your patner business org.
2.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.
3.Create user-friendly aliases for packaging IDs and include those aliases in your Salesforce DX project file and
when running CLI packaging commands.
4.Make use of Scratch Orgs and other source control systems for development instead using the Namespace Org.
5.Always test using Beta package before you actually upgrade package.
Advantages and Gaps of 2GP :
============================
1.Define one Namespace for your company and use it for every package you develop.
2.With 2GP, you can build your application as separate modules.
Smaller functional modules are always easy to develop, test and maintain.
3.Can make use of the flexibility development with the help of source control systems that you use.
Gaps :
1.Component's can't be deleted from packages.
2.Package versions can't be deprecated.
3.Apex VersionProvider isn't supported.
4.A default language for labels in packages can't be specified.