- Salesforce CLI (SFDX)
- Installation
- SFDX Command
- Listing all the commands
- Update the SFDX
- Getting Help on SFDX Commands
- Authorize an org using the web login flow
- Listing all the orgs
- Listing Org Aliases
- Opening an org
- Changing the default org for a Salesforce Project
- Deleting a scratch org
- Creating SFDX Project
- Deploy Changes to Developer Edition Org or a Trailhead Playground
- Scratch Org
- Running Apex Anonymous Code
- Debugging Apex Code
- Reference
- First you need to install latest version of Node.js.
- After that you can install Salesforce CLI.
sfdx commands
sfdx update
sfdx {command} --help
sfdx {command} -h
sfdx force:auth:web:login -h
USAGE
$ sfdx auth:web:login [-i <string>] [-r <url>] [-d] [-s] [-a <string>] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]
OPTIONS
-a, --setalias=setalias set an alias for the authenticated org
-d, --setdefaultdevhubusername set the authenticated org as the default dev hub org for scratch org creation
-i, --clientid=clientid OAuth client ID (sometimes called the consumer key)
-r, --instanceurl=instanceurl the login URL of the instance the org lives on
-s, --setdefaultusername set the authenticated org as the default username that all commands run against
--json format output as json
--loglevel=(trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL) [default: warn] logging level for this command invocation
DESCRIPTION
If you specify an --instanceurl value, this value overrides the sfdcLoginUrl value in your sfdx-project.json file. To specify a My Domain URL, use the format MyDomainName.my.salesforce.com (not
MyDomainName.lightning.force.com). To log in to a sandbox, set --instanceurl to https://MyDomainName--SandboxName.sandbox.my.salesforce.com.
ALIASES
$ sfdx force:auth:web:login
EXAMPLES
sfdx auth:web:login -a TestOrg1
sfdx auth:web:login -i <OAuth client id>
sfdx auth:web:login -r https://MyDomainName--SandboxName.sandbox.my.salesforce.com
List all orgs you’ve created or authenticated to. This command only shows active
scratch orgs. To view expired scratch orgs, use --all
flag with it.
sfdx force:org:list
sfdx force:org:list --all // View expired scratch orgs too
sfdx force:org:list
=== Orgs
ALIAS USERNAME ORG ID CONNECTED STATUS
----------- -------------------- -------- ----------------
DD-ORG jdoe@dd-204.com 00D...OEA Connected
(D) devhuborg jdoe@mydevhub.com 00D...MAC Connected
ALIAS SCRATCH ORG NAME USERNAME ORG ID EXPIRATION DATE
---------- ------------ -------------------------- --------- ----------
my-scratch Your Company test-wvkm5z113@example.com 00D...UAI 2017-06-13
(U) scratch208 Your Company test-wvkm5z113@example.com 00D...UAY 2017-06-13
-
The top section of the output lists the
non-scratch orgs
that you’ve authorized, including Dev Hub orgs, production orgs, and sandboxes. -
A
(D)
on the left points to thedefault Dev Hub org
username. -
The lower section lists the active scratch orgs that you’ve created.
-
A (U) on the left points to the
default scratch org
username.
sfdx alias:list
Alias Value
─────────── ─────────────────────────────────────────
adil1535 a@hotmail.com
jonmortgage j@w.co.uk.dev
sfdx force:org:open // Open default org
sfdx force:org:open --targetusername Open
sfdx force:org:open -u DevHub
sfdx force:org:open -u FullSandbox
sfdx force:org:open -u MyScratchOrg
sfdx force:config:set defaultusername=orgalias
sfdx config:set defaultusername=me@my.org defaultdevhubusername=me@myhub.org
sfdx config:set defaultdevhubusername=me@myhub.org
001
002
sfdx force:org:delete -u me@my.org
sfdx force:org:delete -u MyOrgAlias -p
USAGE
$ sfdx force:org:delete [-p] [-v <string>] [-u <string>] [--apiversion <string>] [--json] [--loglevel
trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]
OPTIONS
-p, --noprompt no prompt to confirm deletion
-u, --targetusername=targetusername username or alias for the target org; overrides default target org
-v, --targetdevhubusername=targetdevhubusername username or alias for the dev hub org; overrides default dev hub
--apiversion=apiversion override the api version used for api requests made by this command
--json format output as json
--loglevel=(trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL) [default: warn] logging level for this command invocation
DESCRIPTION
To mark the org for deletion without being prompted to confirm, specify --noprompt.
This command creates a Salesforce DX project in the specified directory or the current working directory. The command creates the necessary configuration files and folders.
sfdx force:project:create -n {projectname}
sfdx force:project:create -n geolocation
$ sfdx force:source:deploy -p path/to/source
$ sfdx force:source:deploy -p .\force-app\
$ sfdx force:source:deploy --sourcepath .\force-app\
sfdx force:org:create -f project-scratch-def.json -a MyScratchOrg --setdefaultusername
sfdx force:source:push --targetusername my-other-scratch-org
sfdx force:source:pull
sfdx force:user:password:generate --targetusername <username>
sfdx force:user:display -u <username>
- First go to lwc folder
cd .\force-app\main\default\lwc\
- To create a Lightning web component, pass --type lwc to the command.
- If you don’t include a --type value, Salesforce CLI creates an Aura component by default.
$ sfdx force:lightning:component:create -n mycomponent --type lwc
001
002
003
sfdx force:apex:execute -f .\scripts\apex\hello.apex
In VS Code, you need to open the file, and while on that file, select the Execute Anonymous Apex with Editor Content
option.