How the heck do I set up a scratch org using sfdx? Well, you're in the right place.
Preparation
Firstly, you will need to have SFDX (Salesforce CLI) installed and VS Code. You will also need your own Salesforce DevHub instance setup (need a hand with setting up your dev hub? check out this trailhead unit.
Create a Salesforce DX Project
Ok, now we are setup lets get into it. The first step is to create an (SF)DX project.
sfdx force:project:create -n YOUR_PROJECT_NAME
Auth your DevHub
Next, we need to connect our DevHub with the new project
sfdx force:auth:web:login -d -a ALIAS_FOR_YOUR_DEV_HUB
-
-dsets this as the default Dev Hub. -
-asets this alias for the org. (strongly recommended)
If you have already auth'd, set your default username using
sfdx force:config:set defaultdevhubusername=lukesfakeemail@force.com
Login To Sandboxes
In addition to DebHubs, we can also connect to standard Salesforce Sandboxes. This can be handy when it comes to pulling components into your scratch org
sfdx force:auth:web:login -r https://test.salesforce.com -a ALIAS_FOR_YOUR_SANDBOX
You may also choose to change the default https://test.salesforce.com url to a custom domain if you have set one up.
Remember, don’t use the
-dflag. If you do, the CLI thinks the org is your Dev Hub, and then you’ll see an error when you try to create a scratch org.
Create your scratch org
Now for the fun part, creating your scratch org.
if you want to set the scratch org name, or adjust other config options, edit the
./config/project-scratch-def.jsonfile before progressing. Later in this series we will properly cover the cool things we can achieve using theproject-scratch-def.jsonfile.
sfdx force:org:create -s -f config/project-scratch-def.json -a ALIAS_FOR_SCRATCH_ORG -d 30 -w 10
-
-ssets this as the default sratch org -
-fsets the location for the config file (to build the org) -
-asets the alias for the scratch org -
-dsets the expiry to 30 days -
-wsets the wait time to 10mins
If you already scratch'd an org
sfdx force:config:set defaultusername=lukesfakeemail@force.com
Assign Permission Set
Before you can start pushing code, we have to set up some permission sets to allow us.
sfdx force:user:permset:assign -n NAME_OF_PERMISSION_SET
most likely named
SalesConsoleUseron default scratch orgs
And there we have it, you've successfully setup a new SFDX Project and connected it to a scratch org. In part 2 we will check out how we can push
TL:DR Commands
create new sfdx project
sfdx force:project:create -n YOUR_PROJECT_NAME
auth a devhub
sfdx force:auth:web:login -d -a ALIAS_FOR_YOUR_DEV_HUB
login to a sandbox
sfdx force:auth:web:login -r https://test.salesforce.com -a ALIAS_FOR_YOUR_SANDBOX
create a new scratch org
sfdx force:org:create -s -f config/project-scratch-def.json -a ALIAS_FOR_SCRATCH_ORG -d 30 -w 10
assign a permission set
sfdx force:user:permset:assign -n SalesConsoleUser
Latest comments (0)