I'm trying to connect to my Trailhead playground org with the Salesforce CLI on VS Code. Here's what I've done:
I created the project then clicked on Authorizing a dev hub. I was prompted for a login – which I successfully authenticated then the browser window redirected to <salesforce org>/lightning/setup/SetupOneHome/home
.
However, when I try to Run a SOQL query I get the following:
I suspect it's an issue with my computer setup, because when I tried creating a separate project entirely I got the same error. Following this didn't help me either.
Can anyone point me in the right direction so I know how to properly authenticate?
Best Answer
You need to set the org with
defaultusername
, notdefaultdevhubusername
(the latter is used for creating packages and scratch orgs, the former is for SOQL, retrieve, deploy, etc).To set the value, press Ctrl+Shift+p, then choose "SFDX: Set a Default Org" (you can type in "default org" to quickly find the command), then select your trailhead username. This will set the default user name and allow the other commands to work. Alternatively, click on the Terminal (Ctrl+Shift+~), then type in:
In the future, make sure you use "SFDX: Authorize an Org" if you want to specify a development org, and "SFDX: Authorize a Dev Hub" for setting a Dev Hub org.