Using SalesforceDX (SFDX) with non Scratch Orgs

Use SFDX with non scratch 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.


  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. Do I need to replace jit11 with my-devhub-org in the command below?
    sfdx force:mdapi:retrieve -r metadata -u jit11 -k metadata/package.xml

  3. 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?

  4. We have created a SSL Certificate and added it to Production DevHub Org and we are able to login to DevHub Org using JWT:grant.

    We have used same SSL certificate and server.key and configured the same steps in sandbox as well. However, when we try to do JWT:grant, we are getting following error message:
    ERROR: This org appears to have a problem with its OAuth configuration. Reason: invalid_grant – audience is invalid
    loginUrl: https://eis1–,
    privateKey: D:\Projects\XXXX\test\server.key.

    Could you please let us know whether we can do JWT:grant in sandbox as well. If yes, is there any other setting we require to do in order to fix this issue in sandbox.

  5. In our Dev Sandbox, we have enabled comminuties. In this sandbox we are trying to create a SFDX package having community configuration. For this package, we are trying to generate a package version.

    However, the SFDX package generation asks us to enable communities. Below is the error:

    Error: You need to enable communities to be able to install Lightning Pages of type CommPbjectPage.

    We did not enable communities in DevHub yet.

    Is Package and package version generated only from DevHub? Not from a lower sandbox?

    My question is why do I need to enable community in prod to test / generate package in DEV?

    Could you please help me on this.

  6. Hi Jitendra,
    I have a question on deployment strategy for dx. We are currently have so much issues with Copado where deployers have to manually update shared pages so as not to overwriting other’s changes to page layout. So we are looking at a sfdx to simplify the deployment process. Dx can solve many of our challenges, but to address the the issues with shared components, I initially thought we could use GitHub to resolve merge conflicts which would required GitHub repository with at the org level which kind of defeats the purpose of DX. Later I was told of an open source project call force DI started by Andy Fawcett which would solved all of our problems. But I don’t know how big of an adoption currently force DI has. I would welcome any comments you have on this topic.


  7. Hi Jitendra,

    I am getting below error while deploying a lightning web component from visual studio.

    Error:No base file for markup://c:firstWebComponent

    Please help me.


  8. Great articles, really helpful . Could you please let me know how to migrate approval processes from full sandbox to developer sandbox via SFDX ?

Leave a comment

Your email address will not be published. Required fields are marked *

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