Get started with SFDX
Step 1: Enable Dev Hub for your org:
Earlier this feature was not available in free developer editions but only in paid production orgs which kinda made it difficult to try out but no more. Now it is available even in DE orgs. So click on Set up-> Search for ‘Dev Hub’ and click on it. Then toggle the switch to on and your Dev Hub would be enabled. Once enabled, it can’t be disabled but that’s okay. Mine is already enabled so you will see in the video that the toggle switch is disabled.
Why enable Dev Hub?
Enabling Dev Hub allows us to create Scratch Orgs, which is crucial for SFDX and scratch orgs support SFDX but not sandboxes or production. Now you must be asking what are scratch orgs? I heard of sandbox org, production orgs, full copy sandbox orgs, partial copy sandbox orgs but what the hell is a scratch org?
Ever heard of the term let’s start from scratch? or scratch pad? something similar? That’s what it means. A scratch org is ephemeral (lasts for max 30 days) in nature, meaning it is a temp org meant specifically for your development of a new project or a new feature. It is a clean slate. It can also be used for unit testing though. Spin up a new scratch org just to test your features before moving them to staging. Why is it needed for SFDX? A scratch org is capable of tracking changes, be it an Apex Class, a lightning component or a custom field creation or change to the page layout. It can track everything so that when the need arises you can simply pull all those changes from your scratch org to your IDE and push them to your VCS (Version Control System). Dont worry I will show you how to do that.
Step 2: Download and install Salesforce CLI, VS Code and Salesforce Extensions for VS Code:
Follow this link.
Salesforce CLI allows your IDE to talk to your Salesforce orgs via commands on terminal. If you get the extension for VS Code then you don’t need to type commands on the terminal but it kinda looks cool so you can do that if you want. Check out the video for more details. Kindly note, my instructions here are primarily for MacOS but these things work on other platforms too.
Step 3: Authorise your DevHub org and set it up as default with an alias:
So you have enabled Dev Hub in your org and set up Salesforce CLI, VS Code and the SFDX extension. Now you need to authorise your org (where you enabled DevHub) and set it as a default and create an alias for it. Aliasing is not mandatory but it will save you a lot of effort when running subsequent commands. You can choose to authorise your org via terminal (MacOS) or use the SFDX extension. The terminal command is as follows:
sfdx force:auth:web:login -d -a DevHub
Here -d indicates you’re setting this org as a default DevHub org and -a lets you set up an alias for it. Here the alias is DevHub. Whatever is written before simply means you wanna authorise a DevHub org (or for that matter any org) via web login. As soon as you fire this command, your default browser window will open where you need to supply the credentials for your DevHub org. Check the video for more details.
So now you know how to enable DevHub in your org (even Developer Edition org) and how to use terminal as well as SFDX extension for VS Code to authorise a DevHub. You have also seen (in the video) how to see a list of the orgs you are connected to via the CLI.
In my next post, I will continue with this and show you how to create a project, how to create a scratch org and how to pull and push changes from and into your scratch org. Until then go ahead and practice authorising your Dev Hub org.