Using SalesforceDX (SFDX) with non Scratch Orgs

Author posted by Jitendra on Posted on under category Categories Salesforce and tagged as Tags , with 6 Comments on Using SalesforceDX (SFDX) with non Scratch Orgs

How to use SalesforceDX (SFDX) with Sandbox, Developer and Production Orgs

Use SFDX with non scratch Orgs

We have gone through few blog posts about SFDX and its capabilities in past. In this post, I will explain steps on how to use SFDX with developer, Sandbox or Production Org. In short we will discuss how to use SFDX with non Scratch Orgs. We would be using official Salesforce IDE for SFDX, which is VSCode.

Assumption – VSCode extension is already installed in your VSCode.

  1. Create SFDX project in VSCode

Open VScode and press cmd+Shift+p, It will give some option. Select SFDX: Create Project.

SFDX : Create Project
SFDX : Create Project

Next screen will ask for project name and then location where to save.

SFDX Project Name
SFDX Project Name

Now, its time to know some basic SFDX commands. You can refer this post for SFDX crash course.

Using SFDX with Sandboxes

If you want to use SFDX with Sandbox, then open file sfdx-project.json in VScode and change sfdcLoginUrl to or my domain URL if SSO is configured.

2. Authenticate Developer Account with SFDX

Run SFDX command in VSCode
Run SFDX command in VSCode

Before authenticating new org, its always good idea to check if its already authenticated using below command

sfdx force:org:list

if not, then run this command to authenticate Salesforce developer org

sfdx force:auth:web:login --setdefaultdevhubusername --setalias my-devhub-org

3. Create package.xml
below is sample package.xml, It contains Lightning Component and Flow

4. Retrieve Metadata

I have created metadata folder in my project where package.xml exists. By running below command, I get zipped file of metadata retrieved.

sfdx force:mdapi:retrieve -r metadata -u jit11 -k metadata/package.xml
  • -u : Which Salesforce Org to be used by Salesforce DX
  • -r : Where zip file should be saved
  • -k : List of components to be retrieved using package.xml

problem with above command is that, it gives zip file. You would need to unzip it every time. To save my time, What I do is, I create a command / batch file to retrieve metadata & at same time unzip it. Below is content of file to unzip metadata

running above file is straight forward in windows operating system, but in Mac, we need to let OS know that metadata_r.command file is executable file by running below command. Make sure to run this command from Terminal and not from VSCode.

chmod +x mdapi_r.command

And command / batch file can be executed in Mac using

bash filename

5. Deploy Metadata

Below command can be used to deploy component in non scratch Salesforce instances

sfdx force:mdapi:deploy -c -f ../mdAPIZip/ -u jit11 -w 10
sfdx force:mdapi:deploy -c -d ../mdAPIZip/unpackaged -u jit11 -w 10


  • -u : Which Salesforce Org to be used by Salesforce DX
  • -f : Zip file location containing metadata and package.xml
  • -c : Check only flag, Package would be validates only
  • -w : Wait time in minute for operation to be completed
  • -d : Folder location of non-zipped files, with package.xml in root

To know more about how to deploy to Developer, Sandbox or Production org (non scratch Org) using SFDX, refer this post.

Related posts

6 thoughts on “Using SalesforceDX (SFDX) with non Scratch Orgs”

  1. Great article!

    DX has a lot of power in force:source:pull/push commands since they get rid of maintaining a template file but those don’t work with non-scratch orgs.

  2. After the final step, once we retrieve the package should we use Ant to deploy? Or Has salesforce come up with deploying metadata as well to the destination org?

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.