Newer Version Available

This content describes an older version of this product. View Latest

Customize Package Installs and Uninstalls Using Scripts

Customize a package install or upgrade by specifying an Apex post install script to run automatically after a subscriber installs or upgrades a 2GP managed package. You can also specify an Apex uninstall script to run automatically when a subscriber uninstalls a 2GP managed package.

For more information, see Running Apex on Package Install/Upgrade and Running Apex on Package Uninstall.

Specify post install and uninstall scripts in the sfdx-project.json file.
1"packageDirectories": [
2      {
3         "path": "expenser-schema",
4         "default": true,
5         "package": "Expense Schema",
6         "versionName": ""ver 0.3.2"",
7         "versionNumber": "0.3.2.NEXT",
8         "postInstallScript": "PostInstallScript",
9         "uninstallScript": "UninstallScript",
10         "postInstallUrl": "https://expenser.com/post-install-instructions.html",
11         "releaseNotesUrl": "https://expenser.com/winter-2020-release-notes.html"
12        },
13        ],
14       {
15         "namespace": "db_exp_manager",
16         "sfdcLoginUrl": "https://login.salesforce.com",
17         "sourceApiVersion": "47.0",
18         "packageAliases": {
19             "Expenser Schema": "0HoB00000004CzHKAU",
20             "Expenser Schema@0.1.0-1": "04tB0000000719qIAA"
21          }

You can also use the --postinstallscript and the --uninstallscript Salesforce CLI parameters with the force:package:version:create command. The CLI parameters override the scripts specified in the sfdx-project.json file.

Include the Apex classes for your post-install and uninstall scripts with the metadata in your package.

Note

You can designate an active Dev Hub org user to receive email notifications for Apex gacks, and install, upgrade, or uninstall failures associated with your packages. In Salesforce CLI run sfdx force:package:create --errornotificationusername me@devhub.org or sfdx force:package:update --errornotificationusername me@devhub.org. In Tooling API, use the PackageErrorUsername field on the Package2 object.