Newer Version Available
Workflow for Unlocked Packages
Review and complete the steps in Before You Create Unlocked Packages before starting this workflow.
The basic workflow includes these steps. See specific topics for details about each step.
- Create a DX
project.
1sf project generate --output-dir expense-manager-workspace --name expenser-app - Authorize the Dev Hub org, and create a scratch
org.
1sf org login web --set-default-dev-hub --alias MyDevHubWhen you perform this step, include the --set-default-dev-hub option. You can then omit the Dev Hub username when running subsequent Salesforce CLI commands.
- Create a scratch org and develop the package. You can use VS Code and the Setup UI
in the scratch org to build and retrieve the pieces you want to include in your
package. Navigate to the expenser-app directory, and then run this
command.
1sf org create scratch --definition-file config/project-scratch-def.json --alias MyTestOrg1 --duration-days 30 - Verify that all package components are in the project directory where you want to create a package.
- From the Salesforce DX project directory, create the package.
1sf package create --name "Expense Manager" --path force-app 2--package-type Unlocked - Review your sfdx-project.json file. The CLI automatically
updates the project file to include the package directory and creates an alias based
on the package name.
1{ 2 "packageDirectories": [ 3 { 4 "path": "force-app", 5 "default": true, 6 "package": "Expense Manager", 7 "versionName": "ver 0.1", 8 "versionNumber": "0.1.0.NEXT" 9 } 10 ], 11 "namespace": "", 12 "sfdcLoginUrl": "https://login.salesforce.com", 13 "sourceApiVersion": "59.0", 14 "packageAliases": { 15 "Expense Manager": "0Hoxxx" 16 } 17}Notice the placeholder values for versionName and versionNumber.
Specify the features and org settings required for the metadata in your package using an external .json file, such as the scratch org definition file. You can specify using the --definition-file flag with the sf package version create command, or list the definition file in your sfdx-project.json file. See: Project Configuration File for Unlocked Packages
- Create a package version. This example assumes the package metadata is in the
force-app
directory.
1sf package version create --package "Expense Manager" --installation-key test1234 --wait 10 - Install and test the package version in a scratch org. Use a different scratch org
from the one you used in step
three.
1sf package install --package "Expense Manager@0.1.0-1" --target-org MyTestOrg1 --installation-key test1234 --wait 10 --publish-wait 10 - After the package is installed, open the scratch org to view the
package.
1sf org open --target-org MyTestOrg1
Package versions are beta until you promote them to a managed-released state. See: Release an Unlocked Package.