function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Daniel Rudman 7Daniel Rudman 7 

Salesforce DX - Scratch Connection Invalid Access Token

Hi, we have written a custom DX plugin and are trying to use the injected connection to the scratch org to login and insert some data. We use the access token which is returned by:

this.org.getConnection().getConnectionOptions().accessToken

To authenticate, but get the error:

The following error occurred during deployment: [UnexpectedErrorFault [ApiFault exceptionCode='INVALID_SESSION_ID' exceptionMessage='Invalid Session ID found in SessionHeader: Illegal Session. Session not found, missing session hash: XXXXXXX This error usually occurs after a session expires or a user logs out. ' extendedErrorDetails='{[0]}' ] ]



But then if I do a: sfdx force:org:open - u <scratch_org_username> , then it works. 

Is there a call I can make in our DX plugin to force this refresh or anything else to make it work, without having consumers manually go and perform an open?

I tried everything in the API which I could see as relevant, like refreshAuth, but it did not hellp.

Thanks in advance!