I'm trying to connect to my Trailhead playground org with the Salesforce CLI on VS Code. Here's what I've done:

Created the project then tried authorizing a devhub

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.

enter image description here

However, when I try to Run a SOQL query I get the following:

enter image description here

enter image description here

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?

  • Have you selected a default org? VSC probably doesn't know what org you want to run against.
    – David Reed
    Oct 8 '19 at 18:09

You need to set the org with defaultusername, not defaultdevhubusername (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:

sfdx force:config:set defaultusername=mytrailhead@whatever.com

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.

  • Thanks! But I am not seeing an option to "authorize an org" it's just letting me do devhub
    – Raja
    Oct 8 '19 at 19:51
  • @Raja Try updating to the latest version (check in the extensions tab). Otherwise, you can use the manual command line code also included in this answer; it is saved to the .sfdx configuration folder and will be detected by VS code.
    – sfdcfox
    Oct 8 '19 at 20:06
  • Thanks! That worked!
    – Raja
    Oct 9 '19 at 16:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.