Newer Version Available

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

Workflow for Unlocked Packages

You can create and install an unlocked package directly from the Salesforce command line.

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.

  1. Create a DX project.
    1sfdx force:project:create --outputdir expense-manager-workspace --projectname \ 
    2expenser-app --defaultpackagedir source-folder
  2. Authorize the Dev Hub org, and create a scratch org.
    1sfdx auth:web:login --setdefaultdevhubusername

    When you perform this step, include the ---setdefaultdevhubusername option. You can then omit the Dev Hub username when running subsequent Salesforce CLI commands.

    If you define an alias for each org you work with, it’s easy to switch between different orgs from the command line. You can authorize different orgs as you iterate through the package development cycle.

    Tip

  3. 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.
    1sfdx force:org:create --definitionfile config/project-scratch-def.json --targetusername MyScratchOrg1
  4. Verify that all package components are in the project directory where you want to create a package.
  5. From the Salesforce DX project directory, create the package.
    1sfdx force:package:create --name "Expense Manager" --path source-folder \
    2--packagetype Unlocked --errornotificationusername me@devhub.org
  6. 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": "47.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 --definitionfile flag with the force:package:version:createcommand, or list the definition file in your sfdx-project.json file. See: Project Configuration File for Packages

  7. Create a package version. This example assumes the package metadata is in the force-app directory.
    1sfdx force:package:version:create --package "Expense Manager" \
    2--installationkey test1234 --wait 10
  8. Install and test the package version in a scratch org. Use a different scratch org from the one you used in step three.
    1sfdx force:package:install --package "Expense Manager@0.1.0-1" --targetusername MyTestOrg1 \
    2--installationkey test1234 --wait 10 --publishwait 10
  9. After the package is installed, open the scratch org to view the package.
    1sfdx force:org:open --targetusername MyTestOrg1

Package versions are beta until you promote them to a managed-released state. See: Release an Unlocked Package.