Salesforce DX Palette and CLI Commands

Frequently used palette commands. To invoke and run a command in the Command Palette from Salesforce Extensions for VS Code, press Ctrl+Shift+P (Windows or Linux) or Cmd+Shift+P (macOS) and type SFDX.

  • SFDX: Get Apex debug logs – To download an Apex Debug Log from the Salesforce servers
  • SFDX: List all Aliases – Displays aliases of all currently connected orgs

Salesforce CLI commands to execute in the Terminal:

  • sfdx version – Displays CLI and Node version.
  • sfdx update – To update CLI.
  • sfdx force:org:list – Lists all currently connected orgs.
  • sfdx force:org:display –targetusername UserName – To view authentication information about an org. If you have set a default username, you don’t have to specify the –targetusername parameter. If you have set an alias for an org, you can specify it with the –targetusername parameter sfdx force:org:display -u my-scratch-org –verbose – To get more information, such as the Salesforce DX authentication URL, include the –verbose parameter. However, –verbose displays the Sfdx Auth Url only if you authenticated to the org using auth:web:login and not auth:jwt:grant.
  • sfdx force:org:create -d 30 -f .\config\project-scratch-def.json – Create a scratch org to expire in 30 days, default 7, min 1. -f is for file.
  • sfdx force:org:create –setdefaultusername –setalias AliasName –definitionfile config/project-scratch-def.json – To create a new scratch org with our definition file and set it as the default org for CLI commands a project.
  • sfdx force:org:open -u username/alias – To open an org.
  • sfdx force:org:delete -u scratchorgusername – Mark a scratch org for deletion.
  • sfdx force:limits:api:display -u devhubusername – To check the limits.
  • sfdx force:alias:list – Displays aliases of all currently connected orgs.
  • sfdx force:alias:set myalias=org-username@example.com – To set or reset org alias.
  • sfdx force:auth:web:login -a AliasName -d – The -d option makes the org as default for all subsequent commands and -a creates the AliasName. Then in the sfdx-config.json file it will stores the alias name as { “defaultusername”: “AliasName” } for dev orgs and { “defaultdevhugusername”: “AliasName” } for DevHub orgs.
  • sfdx auth:web:login –setdefaultusername –setalias AliasName – Set the authenticated org as the default username that all commands run against.
  • sfdx auth:web:login –setdefaultdevhubusername –setalias DevHub – Set the authenticated org as the default dev hub org for scratch org creation.
  • sfdx config:set defaultdevhubusername=DevHub –global – To use this DevHub as the default for all Salesforce DX projects on this computer so that you don’t have to specify the –targetdevhubusername | -v CLI argument for each command.
  • sfdx force:project:create –projectname sfdx-chan – Use the Salesforce CLI to create a skeleton project structure named sfdx-chan.
  • sfdx force:source:retrieve –manifest assets/package.xml –targetusername DevHub –wait 10 – Retrieve metadata from an org based on the items specified in the package.xml file.
  • sfdx force:source:push – Push local source metadata to org/scratch org. Note that without specifying the –targetusername | -u flag then the CLI uses the default org/scratch org for the project.
  • sfdx force:source:pull -f – Pull metadata from org/scratch org to local project.
  • sfdx force:user:permset:assign –permsetname DreamHouse – Assign the default scratch org user access to the DreamHouse app.
  • sfdx force:data:tree:export –targetusername DevHub –outputdir assets/data –query “SELECT Id, Name, Email__c, Phone__c, Mobile_Phone__c, Title__c, Picture__c, ( SELECT Id, Address__c, Assessed_Value__c FROM Properties__r ) FROM Broker__c” – To export required (property and broker in this example) records and save them as a JSON file in the sub-folder assets/data, this saves the tedious task of creating records to work with every time you create a new scratch org or sandbox.
  • sfdx force:data:tree:import -f assets/data/Broker__c-Property__c.json – Import the sample data from the assets folder.
  • sfdx force:apex:test:run –codecoverage –resultformat human –wait 2 – Run Apex tests and display code coverage results.
  • sfdx force:source:deploy – To deploy metadata to non-scratch orgs, use this Salesforce CLI command rather than force:source:push.
  • sfdx force:source:deploy –targetusername DevHub –sourcepath force-app – Deploy local source metadata to Dev Hub org.

See full list of Salesforce CLI command reference for various namespaces here.