Salesforce CLI

Salesforce CLI is a powerful command line interface that simplifies development and build automation when working with Salesforce org. With Salesforce CLI, you can :

  1. Create and Manage orgs
  2. Create Scratch orgs
  3. Synchronize metadata to and from orgs
  4. Create & install packages
  5. Create & execute tests
  6. Import and export data

To download Salesforce CLI, visit and download for your operating system.

Some of the most commonly used Salesforce CLI commands are :

  1. sfdx force --help
    1. All available topics
  2. sfdx force:doc:commands:list
    1. All available commands
  3. sfdx force:auth:web:login -d -a DevHub
    1. Authorize Dev Hub org
    2. -d is set default Dev Hub org
    3. -a is for setting alias
    4. DevHub is alisa
  4. sfdx force:org:open -u DevHub
    1. Login to DevHub org
  5. sfdx force:auth:web:login -r -a FullSandbox
    1. Login to Sandboxes
    2. use FullSandbox word if you have set alias else use username
  6. sfdx force:project:create -n geolocation
    1. Creates a folder called geolocation, and scaffolds a new project with all assets in the proper folder structure
    2. geolocation is a name of the project
  7. sfdx force:org:create -s -f config/project-scratch-def.json -a GeoAppScratch
    1. The -s option indicates that you want this scratch org to be the default org for this project when running Salesforce CLI commands. To use a different org on a per command basis, you can specify the -u argument and specify another alias.
    2. The -f option is the path to the project scratch org configuration file.
  8. sfdx force:data:record:create -s Account -v "Name='Marriott Marquis' BillingStreet='780 Mission St' BillingCity='San Francisco' BillingState='CA' BillingPostalCode='94103' Phone='(415) 896-1600' Website=''"
    1. Create Account record
  9. sfdx force:data:tree:export -q "SELECT Name, BillingStreet, BillingCity, BillingState, BillingPostalCode, Phone, Website FROM Account WHERE BillingStreet != NULL AND BillingCity != NULL and BillingState != NULL"-d ./data
    1. To retrieve data in a file.
  10. sfdx force:data:tree:import--sobjecttreefiles data/Account.json
    1. Import json data
  11. sfdx force:apex:class:create -n AccountSearchController -d force-app/main/default/classes
    1. Create apex class with name AccountSearchController in directory force-app/main/default/classes
  12. sfdx force:source:push
    1. Push change to the org
  13. sfdx force:lightning:event:create -n AccountsLoaded -d force-app/main/default/aura
    1. Create lightning event with name AccountsLoaded in directory force-app/main/default/aura
  14. sfdx force:lightning:component:create -n AccountSearch -d force-app/main/default/aura
    1. Create lightning event with name AccountSearch in directory force-app/main/default/aura
  15. sfdx force:source:pull
    1. To pull source from the org to local system
  16. sfdx force:user:permset:assign -n Geolocation -u GeoTestOrg
    1. Assign permission set Geolocation
  17. sfdx force:org:display -u TempUnmanaged
    1. View the configuration data for the scratch org
  18. sfdx force:user:password:generate -u TempUnmanaged
    1. Create a password
  19. sfdx force:mdapi:retrieve -s -r ./mdapipackage -p DreamInvest -u TempUnmanaged -w 10
    1. Create package in the folder mdapipackage
    2. DreamInvest in the package in the org
    3. TempUnmanaged is the org alias
  20. sfdx force:mdapi:convert -r mdapipackage/
    1. un package the code in folder mdapipackage and add to the force-app folder
  21. sfdx force:org:delete -u TempUnmanaged
    1. Deleting the scratch org TempUnmanaged
  22. rm -rf mdapipackage
    1. Clean up your project by deleting the Metadata API source
  23. sfdx force:org:list
    1. list of all orgs

If you have question regarding Salesforce CLI, please comment below. Thanks!

Be the first to comment

Leave a Reply

Your email address will not be published.