As developers, we often face many Salesforce DX old dev hubs, scratch and non-scratch orgs in the void. Some of these are expired or with invalid access and are making a mess in our VSCode environment.
Even if you delete your current installation of Salesforce DX CLI, you will still end up with the orgs and this will be helpful. So time to do some tidying.
Normally, Salesforce DX only allows the deletion of scratch orgs, not other org types. For that, you use the following command.
sfdx force:org:delete -u dev-hub
Upon creation of a new Dev Hub and attempting to replace the existing dev-hub alias, you can use the following command.
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. First-line in the org list.
So the question is how do you remove a dev-hub org, or any other non-scratch org from the list of orgs in the SFDX CLI?
Salesforce still doesn’t provide commands that can simply solve this: the ability to clean up old orgs that are no longer needed
For the time being, you need to manually clean up the DX configs in the local installation.
Mac/Linux
On mac/Linux, you can find your DX config folder, called .sfdx
in your user home directory.
cd ~/.sfdx
Windows
On windows, you can press the Windows Key + R and type%USERPROFILE%\.sfdx
, then press Enter.
In that folder, there are a host of .json
files, named for the username of the admin user you registered for that org. For our case, this instance was called smtDarkoSandbox@dx.com, which has the following file:
smtDarkoSandbox@dx.com.json
Inside the file are the hashes for the current access token, refresh token, and all the other OAuth goodness that allows DX to access your org. So I simply deleted that file.
Command to delete the file:
> rm peter@dx.pilot.json
That appears to have cleaned it all up, and I’m no longer bothered by the “invalid grant” or “RefreshTokenAuthError” messages.
Want to learn more?
Learn about How to Bypass the trigger with apex
Read more about Salesforce CLI Command Reference
Check out this Trail: App Development with Salesforce DX
Leave a Reply