I know that it is possible (whilst you have a working connection) to explicitly set a password for a scratch org user. However, I hadn't done this. Is there a way to recover access to a scratch org where a password was not assigned and the local storage for the scratch org connection (in the user's home directory ".sfdx" folder) has been lost?

I know the .sfdx folder contains a file per scratch org, named after the test-blah@example.com username. For example:


I also know that the basic detail for the scratch org can be recovered from the Dev Hub using a query like:

SELECT LoginUrl, ExpirationDate, Name, SignupUsername, ScratchOrg, SignupInstance FROM ScratchOrgInfo WHERE SignupUsername = 'test-cm4ssgpssyoo@example.com'

However, when you look in the JSON file it includes some additional values:

    "orgId": "00D0P000007uuFAKEI",
    "accessToken": "bc59d79aa7c8d0b1acc21999186ba9760f95ca358b06246c8774e85a12c6ab74cc120c1b3b9f4c37604c6fe1adb22a99f39f4cdaefba3e746e03c5585363ad2fd4391e977865fc9ff4094de204944ebcd731773c41d6e872bc45a1ddb74db4faa8aa2db34a627b0d32af2c752f66246a122139be0ef6:cb3ada34338cf3f695c16307d26e0bdb",
    "refreshToken": "6d82eff4339dfe1532e35ddcf53d79d7f07c3p099ca6860dd3ee29d8f7c8c00880c97a1ade02e638855debc3d2a0f1e2e089f0b9b58ece7f282f3262br2d2151ea74f0f34403e3e78b3ae8f5dbc7b944303832eb5b49b79894bf57963c:a8253c3a7302697ea043b4daddy82cee",
    "instanceUrl": "https://some-nonsense-1138-dev-ed.cs88.my.salesforce.com",
    "loginUrl": "https://CS88.salesforce.com",
    "username": "test-cm4ssgpssyoo@example.com",
    "clientId": "PlatformCLI",
    "createdOrgInstance": "CS88",
    "created": "1557932726374",
    "devHubUsername": "my-fake-dev-hub@somewhere.com",
    "isDevHub": false

Specifically, the accessToken and refreshToken values (don't worry, these are fakes for a fake scratch org ID etc.).

It seems that without these tokens I cannot regain access to the scratch org. (The only reason to access the scratch org now is to recover some changes that were otherwise only on the hard drive that failed, causing me to lose the original meta data and JSON file content (and thus scratch org access) in the first place.)

Is there a way to recover access to the scratch org before it expires?

Your Answer

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

Browse other questions tagged or ask your own question.