Skip to content

Latest commit

 

History

History
330 lines (226 loc) · 12.4 KB

sfdx.md

File metadata and controls

330 lines (226 loc) · 12.4 KB

Salesforce CLI (SFDX)

Installation

SFDX Command

Listing all the commands

sfdx commands

Update the SFDX

sfdx update 

Getting Help on SFDX Commands

sfdx {command} --help
sfdx {command} -h

sfdx force:auth:web:login -h

Authorize an org using the web login flow

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

Listing all the orgs

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
Exaple Org listing
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 the default 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.

Listing Org Aliases

sfdx alias:list
Example Output
 Alias       Value
 ─────────── ─────────────────────────────────────────
 adil1535    a@hotmail.com
 jonmortgage j@w.co.uk.dev

Opening an org

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

Changing the default org for a Salesforce Project

sfdx force:config:set defaultusername=orgalias
sfdx config:set defaultusername=me@my.org defaultdevhubusername=me@myhub.org
sfdx config:set defaultdevhubusername=me@myhub.org
VS Code Steps

001

default-org-1

002

default-org-2

Deleting a scratch org

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
To deploy the source files in a directory in Developer Edition Org or a Trailhead Playground
$ sfdx force:source:deploy -p path/to/source
$ sfdx force:source:deploy -p .\force-app\
$ sfdx force:source:deploy --sourcepath .\force-app\

Scratch Org

sfdx force:org:create -f project-scratch-def.json -a MyScratchOrg --setdefaultusername
Step # 01

scratch-org

Step # 02

scratch-org1

Step # 03

scratch-org2

Step # 04

scratch-org3

sfdx force:source:push --targetusername my-other-scratch-org
sfdx force:source:pull
Generating Password
sfdx force:user:password:generate --targetusername <username>
Viewing Password again
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
VS Code Steps

001

vscode-create-lwc-1

002

vscode-create-lwc-2

003

vscode-create-lwc-3

Project Vs Bundle?

Running Apex Anonymous Code

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.

vs-code-annonymous-code

Debugging Apex Code

Get Apex Debug Log

Launch Apex Relay Debugger

Reference