Quick Start: Salesforce DX
These are technical notes I compiled while studying using Trailhead, Salesforce's free self-learning portal.
Set Up Your Salesforce DX Environment
- The Salesforce Developer Experience (DX) is a set of tools that streamlines the entire development cycle. It:
- Improves team development and collaboration,
- Facilitates automated testing and continuous integration, and
- Makes the release cycle more efficient and agile.
- A scratch org is a dedicated, configurable, short-term Salesforce environment that you can quickly spin up to create a new project, feature, or test.
- A Developer Hub (Dev Hub) is the main Salesforce org that a team uses to create and manage scratch orgs.
- Enable a Dev Hub in a Developer Edition or Trailhead Org by following these instructions:
- Log into the target org as an admin. Then, Setup > Quick Find > “Dev Hub” > Enable Dev Hub
- Once enabled, cannot be disabled.
- Enable a Dev Hub in a Developer Edition or Trailhead Org by following these instructions:
- Get the Dev Hub login credentials by following these instructions
- Navigate to “Get Your Login Credentials” tab on the Playground Starter page.
- Follow these instructions to set up Salesforce CLI
- On Mac, this install takes the form of a straightforward, graphical installation of a
.pkg
file - Once installed, confirm by running the following from the command line:
sfdx update
. Output likesfdx-cli: Updating CLI...
indicates the package is installed.
- On Mac, this install takes the form of a straightforward, graphical installation of a
- Log In to the Dev Hub
- Create an alias DevHub by using -a and make this the default org using -d:
sfdx auth:web:login -d -a DevHub
- This will open the Salesforce login page in the web browser
- Logging in to the Dev Hub on that screen will display a message like:
Successfully authorized [email protected]...
After this authentication, the CLI remembers your Dev Hub credentials.
- Logging in to the Dev Hub on that screen will display a message like:
- Create an alias DevHub by using -a and make this the default org using -d:
Set Up the Project on Your Local Machine
- Download a Project from GitHub
mkdir my_sfdx_project
cd my_sfdx_project
git clone https://github.com/trailheadapps/dreamhouse-lwc.git
cd dreamhouse-lwc
- Create a Branch for your project
- Creating a branch is a best practice as defined by GitHub Flow. It helps ensure your Master branch is a clean and production-ready version of your code.
git checkout -b my_branch
Create and Test Our Scratch Org
- Create a scratch org, set it as default, and give it an alias:
sfdx force:org:create -s -f config/project-scratch-def.json -a dreamhouse-org
- As output, you will receive the org ID and the username. No passwords are needed because Salesforce DX uses cached authentication tokens
- Open the just-created scratch org:
sfdx force:org:open
- Because the scratch org was set as default using the
-s
flag, the system stores the authentication token and uses it to log in for you. - The scratch org will open in a new window.
Push Source Metadata to Scratch Org
- Push the dreamforce-lwc project into the scratch org:
sfdx force:source:push
Assign a Permission Set to the DreamHouse App
- The Dreamhouse app Salesforce set up for this demo uses a permission set to provide access. Assign the permission set by running the command:
sfdx force:user:permset:assign -n Dreamhouse
Import Test Data
- Import sample data by running this command:
sfdx force:data:tree:import --plan data/sample-data-plan.json
- Use force:data commands to manipulate records in your org through the command-line terminal window.
Note: Your Dev Hub org edition determines how many scratch orgs can be created daily.