37

In the Salesforce DX pilot, every pilot participant was given a temporary dev hub org. These orgs expired, were destroyed, and sent back to the matrix in advance of the open beta.

I had an existing installation of the Salesforce DX cli, and I found after upgrading, my old dev hub was still hanging about showing it had an invalid grant. So time to do some tidying.

enter image description here

Normally, to delete a scratch org, you'd just delete it. I wasn't sure, so first I attempted to remove it that way:

sfdx force:org:delete -u dev-hub

Only this didn't work. Salesforce DX only allows the deletion of scratch orgs, not other org types.

I then created my new dev hub and attempted to replace the existing dev-hub alias by doing...

sfdx force:auth:web:login -a dev-hub -d

Only I was left with it still registered in the list, just with no more alias.

enter image description here

How do you remove a dev-hub org, or any other non-scratch org from the list of orgs in the SFDX CLI?

  • 6
    Is that your music collection hiding in the back of the screenshots? – Daniel Ballinger Aug 3 '17 at 1:29
  • 2
    Uh...wow! Good eye. LOL. – pchittum Aug 3 '17 at 16:05
36

It would be nice for this to be something in the actual CLI commands: the ability to clean up old orgs that are no longer needed.

For the time being, you need to manually cleanup the DX configs in the local installation.

On mac/linux, you can find your DX config folder, called .sfdx in your user home directory.

cd ~/.sfdx

On windows, you can use %USERPROFILE%\.sfdx

In that folder there are a host of .json files, named for the username of the admin user you registered for that org. In my case, in this instance it was called peter@dx.pilot, so sure enough, there it was:

peter@dx.pilot.json

Inside the file, or the hashes for current access token, refresh token, and all the other OAuth goodness that allows DX to access your org. So I simply deleted that file:

> rm peter@dx.pilot.json

That appears to have cleaned it all up, and I'm no longer bothered by the "invalid grant" message and the shadow org.

  • I believe SalesforceDX is still in beta state, so I would suggest not to use for big projects. – Rohit Mourya Jul 4 '17 at 18:05
21

It looks like rather than deleting a hub org, you just call:

sfdx force:auth:logout -u <hub alias>

You'll get a warning about being sure you want to log out. Once you do, that hub org will no longer show up in the list.

  • Only downside is that if that was your default, you're left without a default hub if that was your default. Use sfdx force:config:set defaultdevhubusername=<devhubusername> --global to repair – Dave Lyon Apr 16 '18 at 22:05
  • Just wanted to note that this answer is particularly helpful if the org being removed is a non-hub, non-scratch org, that we probably don't want to delete, but only remove from the org list. – SamuelDev Aug 20 '18 at 7:02
  • That 30 day expire on trial hub orgs is a real PITA – Scott Morrison Sep 25 '18 at 7:34
  • This worked for me, as I needed to update the sandbox alias to a new sandbox. Just did the force:auth:logout, then a new force:auth:web:login after that. Thanks. – specimen Dec 17 '18 at 15:09
  • This is the correct answer. Thanks for this. – Arthlete Jul 29 at 20:10
17
D:\...>sfdx force:org:list
=== Orgs
     ALIAS         USERNAME                                    ORG ID              CONNECTED STATUS
───  ────────────  ──────────────────────────────────────────  ──────────────────  ────────────────
     DevHub        daniel.ballinger+devhub@example.com           00D7F0000000001AAA  invalid_grant

I just had my trial Dev Hub org expire (invalid_grant), so I created a new Dev Hub and registered it with sfdx force:auth:web:login -d.

That moved the (D) marker to my new dev hub, but the old one was still hanging around. Peter's solution would have worked, but I thought I'd try a sfdx force:org:delete -u DevHub to see what happens now the old org is no longer the nominated dev hub.

D:\...>sfdx force:org:delete -u DevHub
Enqueue scratch org with name: DevHub for deletion?  Are you sure (y/n)?: y
Successfully deleted scratch org DevHub.

Appears to have worked even though it isn't a scratch org. The old dev hub org no longer appears for a sfdx force:org:list

  • much simpler than the accepted answer, just use the email address (username) if there's no alias. – Aequitas Feb 26 '18 at 23:39
  • My devhub scratch org is expired and I can't delete it using delete command. Receive an error "The Dev Hub org cannot be deleted." when I try to do that $ sfdx force:org:delete -u DevHub Enqueue scratch org with name: DevHub for deletion? Are you sure (y/n)?: y ERROR: The Dev Hub org cannot be deleted. – Patlatus Jul 16 '18 at 10:21
  • Try adding a new valid scratch org first – Daniel Ballinger Jul 16 '18 at 10:26
6

I just ran into this issue while trying to create a scratch org and found a working solution. After I authorized my production DevHub, entering the following allowed me to remove the old TrialDevHub org with the invalid_grant.

~ sfdx force:config:set defaultdevhubusername=mynewdevhub@username.com --global

...

~ sfdx force:org:delete -u TrialDevHub
Enqueue scratch org with name: TrialDevHub for deletion?  Are you sure (y/n)?: y
Successfully deleted scratch org TrialDevHub.

sfdx force:org:list no longer shows my expired TrialDevHub and I can successfully create scratch orgs once again.

This worked using sfdx-cli version 6.0.10-3713d7b on a Mac with node version 8.6.0.

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.