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.
Next screen will ask for project name and then location where to save.
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
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/unpackaged.zip -u jit11 -w 10 or sfdx force:mdapi:deploy -c -d ../mdAPIZip/unpackaged -u jit11 -w 10
where
- -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.
Leave a Reply