0

I have recently installed VS Code and migrated my projects from Eclipse over to VS Code. I'm getting familiarized with the IDE. I've gotten my projects created and authorized and have successfully retrieved metadata and pushed metadata to the orgs.

I am still trying to get a handle on DevHub and scratch orgs. I created a Trailhead playground and enabled DevHub in the Trailhead playground. I went thru the steps to install a sample gallery into a scratch org by cloning a git repo. I've gone thru the trailhead modules on setting this all up, but I'm still struggling to get a full grasp on how this works. Is the only purpose for the DevHub to enable the command line interface? It indicates that the scratch orgs are only good for 7 to 30 days depending on what you set. I set it for 30 days. Is the scratch org deleted after the expiration of the number of days that have been set? The local directory where I cloned the git repo would no longer be connected to an org and would need to be reconnected to a new scratch org and then have the metadata pushed back into the new scratch org, is that correct?

I created a scratch org for the sample gallery that I pulled down from the git repo. I was able to open the project from the terminal using the command sfdx force:org:open

However, today, then I typed it in, it gave me the error Must pass a user and/or OAuth options when creating an AuthInfo instance.

Where can I find the username and how to pass that when running the open org command?

Is there a way to open the scratch org without using the terminal commands and instead use Ctrl + Shift + p and then use the sfdx to search for a command in the UI to open the scratch org? Or, can you only open the scratch org using commands in the terminal?

1

Is the only purpose for the DevHub to enable the command line interface?

Dev Hub is not necessary for the CLI to work. It is necessary for Scratch Orgs to be created (including the push/retrieve commands that work on scratch orgs).

It indicates that the scratch orgs are only good for 7 to 30 days depending on what you set. I set it for 30 days. Is the scratch org deleted after the expiration of the number of days that have been set?

Yes, the orgs are meant to be ephemeral in nature to promote agile development cycles.

The local directory where I cloned the git repo would no longer be connected to an org and would need to be reconnected to a new scratch org and then have the metadata pushed back into the new scratch org, is that correct?

Yes, that would be the intended process.

However, today, then I typed it in, it gave me the error Must pass a user and/or OAuth options when creating an AuthInfo instance.

Did your scratch org expire? If so, you need to create a new one. You can see the list of orgs you have connected via sfdx force:org:list --all, including user names and aliases. You can set one username as the default with sfdx force:config:set defaultusername=username-or-alias.

Is there a way to open the scratch org without using the terminal commands and instead use Ctrl + Shift + p and then use the sfdx to search for a command in the UI to open the scratch org? Or, can you only open the scratch org using commands in the terminal?

Yes, SFDX: Open Default Org does this, assuming you've set it as the default org. You can open any arbitrary org using the terminal command only at this point.

1

Let me divide everything to points

  1. DevHub and Scratch orgs purpose.

In normal world DevHub is basically your production org with switched on "DevHub" which is used to create Scratch Orgs. Besides that it can be used for example to create unlocked packages or 2nd generation packages. DevHub is your Control Center of Scratch Orgs. In the org which have Dev Hub enabled you can check list of your created Scratch Orgs, also you authorize with DevHub organization to create Scratch Orgs through CLI.

Scratch Orgs are as you said temporal organizations that are created using config file which indicates which type of org should be created (Dev, Enterprise, Pro etc) and which features should be turned. They are living for 7-30 days as you said (in reality slightly more than that, like nearly 1 day more).

Purpose of the Scratch Org: because SFDX is code (repository) oriented, your source of truth is the code living in repository. Scratch Org is only temp because the idea was to use 1 Scratch Org to develop 1 "bigger" feature and than move to another clean org after commiting code that cointains information about that feature.

  1. Why you didnt get access to the Scratch org.

That error usally indicates that your Scratch org either expired or you dont have your default username set for Scratch Org that you want access. It can be done with command:

sfdx force:config:set defaultusername=me@my.org

  1. Ctrl + Shift + p and selecting Open Default Org is made exactly for what you want
  • Thank you for the explanation! This was very helpful! – Dman100 May 8 at 19:28

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.