Salesforce CLI is a powerful command line interface that simplifies development and build automation when working with Salesforce org. With Salesforce CLI, you can :
- Create and Manage orgs
- Create Scratch orgs
- Synchronize metadata to and from orgs
- Create & install packages
- Create & execute tests
- Import and export data
To download Salesforce CLI, visit https://developer.salesforce.com/tools/sfdxcli and download for your operating system.
Some of the most commonly used Salesforce CLI commands are :
sfdx force --help
- All available topics
sfdx force:doc:commands:list
- All available commands
sfdx force:auth:web:login -d -a DevHub
- Authorize Dev Hub org
- -d is set default Dev Hub org
- -a is for setting alias
- DevHub is alisa
sfdx force:org:open -u DevHub
- Login to DevHub org
sfdx force:auth:web:login -r https://test.salesforce.com -a FullSandbox
- Login to Sandboxes
- use FullSandbox word if you have set alias else use username
sfdx force:project:create -n geolocation
- Creates a folder called geolocation, and scaffolds a new project with all assets in the proper folder structure
- geolocation is a name of the project
sfdx force:org:create -s -f config/project-scratch-def.json -a GeoAppScratch
- 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.
- The -f option is the path to the project scratch org configuration file.
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='www.marriott.com'"
- Create Account record
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
- To retrieve data in a file.
sfdx force:data:tree:import--sobjecttreefiles data/Account.json
- Import json data
sfdx force:apex:class:create -n AccountSearchController -d force-app/main/default/classes
- Create apex class with name AccountSearchController in directory force-app/main/default/classes
sfdx force:source:push
- Push change to the org
sfdx force:lightning:event:create -n AccountsLoaded -d force-app/main/default/aura
- Create lightning event with name AccountsLoaded in directory force-app/main/default/aura
sfdx force:lightning:component:create -n AccountSearch -d force-app/main/default/aura
- Create lightning event with name AccountSearch in directory force-app/main/default/aura
sfdx force:source:pull
- To pull source from the org to local system
sfdx force:user:permset:assign -n Geolocation -u GeoTestOrg
- Assign permission set Geolocation
sfdx force:org:display -u TempUnmanaged
- View the configuration data for the scratch org
sfdx force:user:password:generate -u TempUnmanaged
- Create a password
sfdx force:mdapi:retrieve -s -r ./mdapipackage -p DreamInvest -u TempUnmanaged -w 10
- Create package in the folder mdapipackage
- DreamInvest in the package in the org
- TempUnmanaged is the org alias
sfdx force:mdapi:convert -r mdapipackage/
- un package the code in folder mdapipackage and add to the force-app folder
sfdx force:org:delete -u TempUnmanaged
- Deleting the scratch org TempUnmanaged
rm -rf mdapipackage
- Clean up your project by deleting the Metadata API source
sfdx force:org:list
- list of all orgs
If you have question regarding Salesforce CLI, please comment below. Thanks!
Leave a Reply