Tuesday 2 January 2018

Salesforce DX | How to Setup Salesforce DX | Creating Scratch Org

Get Started With Salesforce DX
In this post we will talk about how to setup Salesforce DX, How to enable the Dev Hub and create Scratch org. Lets understand what is scratch org ? A scratch org is a dedicated short-term Salesforce environment for development and configuration. Scratch orgs drive developer productivity and collaboration during the development process, and facilitate continuous integration. If you want to learn about SalesforceDx for non-scratch org then please check this post.

Lets get Started with SalesforceDX (SFDX.)

Step 1) Enable Dev Hub

Enable Dev Hub in your org so you can create and manage scratch orgs. You can enable the Dev Hub in any Developer Org, Production and developer Hub Trail Account. Follow below setup to enable dev hub.
  1. Login to your Developer Edition, production or trail org. Then click on Setup.
  2. Search Dev hub in Quick Find and click on Dev Hub.
  3. Then Click on enable button.

Step 2) Install Command Line Interface

    1) Download the CLI from below link and install that.
    2)  In a command window, enter sfdx and validate SFDX is insalled properly.

Step 3) Setup Dev Hub and Set Alias

    1) Login on Dev Hub :  Execute below command in command prompt to authorize the Dev hub with web login flow 

    sfdx force:auth:web:login -d -a DEVHUB
       -d to set Default org
       -a to set alias for the org
DEVHUB login

    Then it will take you to wed browser to login. Then login with your salesforce Dx Account. After login you will get below screen.

        2) Open your DevHub Org: After that you can login with alise Name DEVHUB any time with below command.

    sfdx force:org:open -u DEVHUB

        3) Login in Sandbox: If you want to login in sandbox you can try below command as well

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

        4) View All org: if you want to see all org then try below command
    sfdx force:org:list

Step 4) Create Scratch Org:-

    1) Create Project : Before creating s scratch org we need to create one SFDX base project. Please execute below command to create DX project.

   sfdx force:project:create -n c:\Amit_Salesforce_DX\MyProject

above command will create a folder like below

SFDX Folder Structure

Lets understand the use of each files :-

Configures the source that this local project manages
Determines the configuration of a scratch org, including which features and preferences define its org shape
This folder will contain project

    2) Create Scratch Org : Go to project location then create scratch org with below command

    sfdx force:org:create -s -f config/project-scratch-def.json -a MyFirstScratch

    -s used for scratch org
    -f path the project scratch org confirgutaion File.
    -a alias

    Once Scratch org will ready then you can also see same org in salesforce as well.

   Now your Scratch org is ready. Start your Development in scratch org.

    3) View Scratch Org Configuration: Exeucte below command to see newly created scratch org.

     sfdx force:org:display -u MyFirstScratch

    4) Open Scratch Org Configuration: Exeucte below command to see newly created scratch org.

     sfdx force:org:open -u MyFirstScratch
     5) Change password for Scratch org: if you want to change the password for scratch org. Please check this post.

If you want learn about how to upload the data in Scratch org with Salesforce DX. Please check this post.

If you you looking for Video and PPT. Check here in Salesforce Apex Hours.

Please share your feedback and comment

Amit Chaudhary


  1. Hi Amit,
    Am unable to create the scratch org in from the sandbox and saying Error: You do not have access to the [ScratchOrgInfo] object. ?


    1. You need devHub access tp create scratch org

  2. Hi,
    How do I open the command window?

  3. I am unable to create project