Create an Unlocked Package
After completing this project, you’ll be able to:
- Create an unlocked package using the Salesforce CLI.
- Create a permission set for the unlocked package.
- Deploy a permission set using the Salesforce CLI.
This project assumes that you are familiar with package development. If you haven’t worked on package development, or would like a refresher, see the Package Development Model and Unlocked Packages for Customers modules here on Trailhead. In those modules, you learn the basics of package development, enable Dev Hub in your Trailhead Playground, and install the Salesforce command line interface (CLI), all of which you need to complete this project.
If you’re new to Salesforce DX or want a refresher, work through the Quick Start: Salesforce DX project.
If you completed the Application Lifecycle and Development Models module, you learned that the source of truth for your org is now a package (or multiple packages). With package development, teams are working off of the same metadata package. This becomes especially important when packages include profiles and permission sets. If you don’t include permission sets in your packages, users may not get the right level of application access, potentially delaying deployment as changes get out of sync with other projects.
In this project, you create a Sales unlocked package and include the permission set in the package. To get started, let’s get you the right tools to work through this project.
Before you write any code, you’ll need a code editing tool. Visual Studio Code (VS Code) is a powerful and highly customizable cross-platform editor. The Salesforce Extension Pack for Visual Studio Code replaces the Force.com IDE plug-in for Salesforce development on the desktop. Let’s install Visual Studio Code and set up the extension pack.
Install Visual Studio
- Install Visual Studio Code from https://code.visualstudio.com/Download.
- Open the Visual Studio Code application.
Install the Salesforce Extension Pack for Visual Studio Code
The Salesforce extensions provide features such as code completion, syntax highlighting, Apex debugging, and more for the Lightning Platform.
- In VS Code, click the View menu, and then choose Extensions.
- In the search box, enter
salesforce extension pack.
- Click Install (or Update, if you already have an earlier version of the extension pack installed and it needs to be updated).
- When the extension pack is installed, relaunch Visual Studio Code.
You now have a powerful tool that enables you to do some pretty cool development projects. In this project, you use VS Code for all terminal commands and code editing.
Time to get another new tool to complement your new code editor. Next, you install the Salesforce CLI (or upgrade it, if you already have it installed). You use CLI commands to create scratch orgs and to synchronize source code between orgs and source repositories.
- Install Salesforce CLI from https://developer.salesforce.com/tools/sfdxcli.
- In VS Code, click Terminal > New Terminal.
- Verify that the sfdx-cli version is up to date.
If the Salesforce CLI needs updating, the terminal window displays “Updating CLI from <old version> to <new version>”.
If your Salesforce CLI is already up to date, the terminal window displays the message “...already on latest version”.
You'll be completing this hands-on project in your own personal Salesforce environment, called a Trailhead Playground. Get your Trailhead Playground now by first logging in to Trailhead, and then clicking Launch at the bottom of this page. Your playground opens in a new browser tab or window. Keep the playground window open while you do this project. After you complete the project steps in your playground, come back to this window and click Verify step at the bottom of this page.
Now is a good time to verify that Dev Hub is enabled in your Trailhead playground. You make org configuration changes through your org setup.
- In your playground, click and then select Setup.
- In the Quick Find box, enter
Dev Hub, and then select Dev Hub.
- Click Enable Dev Hub.
- Select Enable Unlocked Packages and Enable Second-Generation Managed Packages.
To authorize your playground, you need your username and password.
- In the Quick Find box, enter
Users, and then select Users.
- Take note of your username. You’ll need your username and password to authorize the Salesforce CLI to connect to your Trailhead Playground. If you know your username and password, you can skip the next step and authorize your playground.
- If you don’t already know your password, check the box next to your name.
- Click Reset Password(s) and then OK. This step sends an email to the address associated with your username. If you don’t see the email, check your spam folder.
- Click the link in the email, and enter a new password.
Now you’re ready to authorize your playground.
- In the VS Code Terminal window, log in to your playground to authorize the Salesforce CLI.
sfdx force:auth:web:login -d -a DevHub
- When the Salesforce login page opens in your browser, enter the username and password, and then click Log In.
- If prompted, click Allow to authorize the Salesforce CLI.
We’ve created some sample metadata for you to use in this project. You’re going to download the project from GitHub, create an unlocked package, make some changes in a scratch org, and then release the package to your Trailhead Playground. If you don’t have a GitHub account, go to https://github.com, enter a username, email, and password, and click Sign up for GitHub.
Clone the project from GitHub into your Documents folder.
- Log in to your GitHub account, if you haven’t already.
- In a web browser, navigate to https://github.com.
- Click Sign In.
- Enter your GitHub credentials, and then click Sign In.
- In VS Code, open the Documents folder.
MacOS: File > Open > Documents
Windows: File > Open Folder > Documents
- Open a new Terminal window by clicking Terminal > New Terminal.
- Clone the GitHub project by running this command:
git clone https://github.com/developerforce/PermSetUnlockedPackage.git
The PermSetUnlockedPackage directory that you just created is your project directory. It already contains a list of items you need to build your unlocked package.
5. Navigate to your project directory by running this command:
Great job! Now that you have the tools, let’s create a permission set.