Salesforcesfdx

Notes on creating unlocked package

Situation:

  • A local sfdx project
  • Linked to github and CirclrCi
  • Deploys to scratch org via CircleCi
  • DevHub enabled and 2nd Generation Packing enabled

Original sfdx-project.json

{
  "packageDirectories": [
    {
      "path": "force-app",
      "default": true
    }
  ],
  "namespace": "",
  "sfdcLoginUrl": "https://login.salesforce.com",
  "sourceApiVersion": "46.0"
}
sfdx force:package:create --name <name> --description <description> --packagetype Unlocked --path <path> --nonamespace

sfdx force:package:create --name "CSTQueue" --description "CSTQueue Package" --packagetype Unlocked --path force-app --nonamespace

This returns a 0Ho1 package Id (this is created and managed in the DevHub)

sfdx-project.json has been updated.
Successfully created a package. 0Ho1n000000k9bcCAA
=== Ids
NAME        VALUE
──────────  ──────────────────
Package Id  0Ho1n000000k9bcCAA

Updated sfdx-project.json

{
    "packageDirectories": [
        {
            "path": "force-app",
            "default": true,
            "package": "CSTQueue",
            "versionName": "ver 0.1",
            "versionNumber": "0.1.0.NEXT"
        }
    ],
    "namespace": "",
    "sfdcLoginUrl": "https://login.salesforce.com",
    "sourceApiVersion": "46.0",
    "packageAliases": {
        "CSTQueue": "0Ho1n000000k9bcCAA"
    }
}

Check by running

sfdx force:package:list
=== Packages [1]
Namespace Prefix  Name      Id                  Alias     Description       Type
────────────────  ────────  ──────────────────  ────────  ────────────────  ────────
                  CSTQueue  0Ho1n000000k9bcCAA  CSTQueue  CSTQueue Package  Unlocked

As yet there is nothing in this package and no version released.

sfdx force:package:version:list --packages 0Ho1n000000k9bcCAA
no results found

Now create a package version

sfdx force:package:version:create -p <packageName> -d force-app 
 --installationkey <password> --wait 10 

sfdx force:package:version:create -p CSTQueue -d force-app  --installationkey <password> --wait 10
sfdx-project.json has been updated.
Successfully created the package version [08c1n000000k9bhAAA]. Subscriber Package Version Id: 04t1n0000021jxDAAQ
Package Installation URL: https://login.salesforce.com/packaging/installPackage.apexp?p0=04t1n0000021jxDAAQ
As an alternative, you can use the "sfdx force:package:install" command.

sfdx-project.json

{
    "packageDirectories": [
        {
            "path": "force-app",
            "default": true,
            "package": "CSTQueue",
            "versionName": "ver 0.1",
            "versionNumber": "0.1.0.NEXT"
        }
    ],
    "namespace": "",
    "sfdcLoginUrl": "https://login.salesforce.com",
    "sourceApiVersion": "46.0",
    "packageAliases": {
        "CSTQueue": "0Ho1n000000k9bcCAA",
        "CSTQueue@0.1.0-1": "04t1n0000021jxDAAQ"
    }
}

Leave a Reply

Your email address will not be published. Required fields are marked *