How to use SalesforceDX (SFDX) with Sandbox, Developer and Production 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.

Create SFDX project in VSCode

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

SFDX : Create Project

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

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 https://test.salesforce.com or my domain URL if SSO is configured.

2. Authenticate Developer Account with SFDX

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

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

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
username: epamadmin@XXXXX.com.devcicd,
clientId: XXXXXXXXXXXXXXXX,
loginUrl: https://eis1–devcicd.my.salesforce.com,
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.

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.