Sub topic 2
Creating Your First Unlocked Package
Assume you know Salesforce metadata, Salesforce CLI, scratch orgs, Git, and Apex tests. An unlocked package groups related metadata into a versioned unit that you can install and upgrade.
Define the package
Create a package directory and add it to sfdx-project.json. Keep the package boundary focused on one capability, such as core data objects or sales automation.
{
"packageDirectories": [
{
"path": "force-app/core",
"package": "Core",
"versionName": "Initial release",
"versionNumber": "1.0.0.NEXT",
"default": true
}
],
"namespace": "",
"sfdcLoginUrl": "https://login.salesforce.com",
"sourceApiVersion": "61.0"
}Create the package record in the Dev Hub:
sf package create --name Core --package-type Unlocked \
--path force-app/core --no-namespace --target-dev-hub MyDevHubThe command creates a package ID and usually adds a packageAliases entry to the project file.
Version numbers and `NEXT`
versionNumber uses major, minor, patch, and build components. 1.0.0.NEXT asks Salesforce to choose the next build number. The generated version might appear as 1.0.0-1.
Build and test a version
Build a beta version and run its Apex tests:
sf package version create --package Core \
--installation-key-bypass --code-coverage \
--wait 20 --target-dev-hub MyDevHubThe --code-coverage option calculates coverage during version creation. Apex in the package must meet Salesforce’s 75% coverage requirement. Add or improve tests before creating another version when coverage is too low.
Install and release
Install a beta version in a test org first:
sf package install --package "[email protected]" \
--target-org MyScratchOrg --wait 20After validation, promote it. Production installations require a released version.
sf package version promote --package "[email protected]" \
--target-dev-hub MyDevHubExercise
What does NEXT do in 1.0.0.NEXT?
Show answer
It tells Salesforce to select the next available build number for that major, minor, and patch version.