Press enter to see results or esc to cancel.

What is Salesforce DX ?

Salesforce DX is a modern tool for building Salesforce applications. It allows Salesforce developers to carry out source driven development. In a source-driven development workflow, the source code can be kept in a version control system such as GitHub,  TFS,  SVN, or any other equivalent source control system.

Salesforce DX includes a “powerful command-line interface and open APIs” which could allow developers to write their own scripts and automation, even if they aren’t familiar with deployment and packaging.

A developer can deploy the source code into a Salesforce instance, referred to as scratch Orgs, using commands provided by the Salesforce DX CLI.

The Salesforce DX CLI also provides commands to push the source code from your local machine to a Salesforce instance, create a Lightning Component Bundle, test Lightning Components, and many others.

Source-driven development makes it easier for developers to work in a team and to adopt Continuous Integration (CI). CI automates the verification of builds (compiling the code and making it ready for a production environment) and helps to detect regression bugs early.

Trailhead link to Salesforce dx

Setting up Salesforce DX

1. Install Salesforce CLI
2. Open the command prompt and check by entering sfdx.

sfdx cli install

3. Update the Salesforce cli to the latest version. If you are installing the latest one it will be updated version only. To update to the latest version enter below command

sfdx update
sfdx cli update
sfdx cli update

Salesforce cli update is in progress. You can see the version change also here. It will take a good amount of time to update based on your internet connection

4. Check if everything is fine or not by this command

sfdx force --help

sfdx-force-help

Now everything is set in your machine perfect and salesforce cli is working fine in your Org.

What are the next steps?

Create Dev Hub org in order to work with Salesforce cli tool. You can create the developer hub org for free (30 days validity) here

developer-hub-org-creation

Once you have created developer hub org note that dev hub feature is enabled by default in your Org. You can check that in your newly created dev hub org (In order to create Scratch Orgs Dev Hub enabling is mandatory)

Setup–> Development–>Dev Hub Observe that Dev Hub is already enabled here. But if you have the business organization (ISV partner or salesforce customer) where you want to work with salesforce cli and scratch orgs then you must enable Dev Hub manually.

devhub

Awesome!!! You have a Dev Hub enabled org ready and what are the next things you have in queue?

The first thing you will need to do is to connect the CLI to Salesforce. The CLI provides commands to connect using web-based OAuth flow, JWT token-based flow, and a sfdx auth URL.    Sounds Interesting????

Execute below command in command prompt to authorize the Dev hub with web login flow

sfdx force:auth:web:login -r https://login.salesforce.com

once you execute this command you will be routed to the browser where you need to provide your credentials to log in. On a successful login, you will see

“Successfully authorized devhub@salesforce.com with org ID
You may now close the browser”

On your command prompt window, now you can close the browser and you can perform all actions in the command prompt.

In order to check which are all orgs connected previously you can execute below command

sfdx force:org:list

–> It will list out all the orgs you have connected till now.

orgs-list

If you want to logout of any of the dev hub orgs ( if you have already connected to multiple and you don’t want to use them anymore) then execute below command (my-hub-org is the alias of the dev hub org)

sfdx force:auth:logout --targetusername my-hub-org

Note: You can alias name with the below command

sfdx force:config:set defaultdevhubusername=devhub -g

Here -g denotes global and hence, by default, for all the DX projects, the same Dev Hub username will be used to create a scratch Org for other DX projects

So finally we have successfully installed salesforce cli, created devhub org and set the default org for the creation of scratch orgs.

Note: Please find all the Salesforce command line interface commands here

sfdx force:doc:commands:list