Show Menu
Cheatography

Salesforce CLI Cheat Sheet (DRAFT) by

Cheat sheet containing common commands for the salesforce CLI

This is a draft cheat sheet. It is a work in progress and is not finished yet.

NOTES

 
All commands are in the force namespace so must be prefixed with
sfdx force:
.

Setup

Create Project
projec­t:c­reate -n dir
Create scratch org
org:create -f config­_file
Generate Password
user:p­ass­wor­d:g­enerate -u user

Migrating Code/C­onfig

Push to scratch org
source­:push
Pull from scratch org
source­:pull
Deploy metadata
mdapi:­deploy -u user -d dir
Retrieve metadata
mdapi:­ret­rieve -u user -r dir
Cancel metadata deployment
mdapi:­dep­loy­:cancel -u user -i job_id

Packaging

Create package
packag­e:c­reate -n name - t type -r dir
Create package version
packag­e:v­ers­ion­:create -p id|alias -d dir -k password
Install package
packag­e:i­nstall -p id|alias -k password
 

NOTES

 
Most commands require a username or alias to indicate the org to operate on, specified via the -u switch.

Authen­tic­ation

Login to an org
auth:w­eb:­login {-a alias} {-d}
Set default dev hub
config:set defaul­tde­vhu­bus­ername=user
Set default scratch org
config:set defaul­tus­ername=user
List valid authen­ticated orgs
org:list
List authen­ticated orgs
auth:list
Open an org
org:open
Logout of an org
org:logout -u user

DATA

Create a record
data:r­ecord -s sobject -v fields
Retrieve a record
data:r­eco­rd:get -s sobject -i id
Update a record
data:r­eco­rd:­update -s sobject -i id -v fields
Query one or more records with SOQL
data:s­oql­:query -q query
Delete a record
data:r­eco­rd:­delete -s sobject -i id
Bulk upsert
data:b­ulk­:upsert -s sobject -i ext_id -f file
 

CONVERT

To source format
mdapi:­convert -r mdpai_dir -d source_dir
From source format
source­:co­nvert -r source_dir -d mdapi_dir

TESTING

Run single test
apex:t­est:run -t class.test
Run all tests in class
apex:t­est:run -t class
Run tests in org namespace
apex:t­est:run -l RunLoc­alTests
Run all tests in org
apex:t­est:run -l RunAll­Tes­tsInOrg
Extract code coverage
apex:t­est:run -c -r human
Run tests when deploying
mdapi:­deploy -u user -r dir -l RunLoc­alTests

OTHER

Display limits
limits­:ap­i:d­isplay
Assign permission set
user:p­erm­set­:assign -n psetname -u user -o users
Execute apex
apex:e­xecute {-f apex_file}
List debug logs
apex:l­og:list
Retrieve debug log
apex:l­og:get -i log_id -n lines
Tail debug logs
apex:l­og:tail -d debuglevel --loglevel level