ToolJet/ToolJet · error · QueryError

Connection Error in Salesforce with validated auth

Error message

Connection Error in Salesforce with validated auth

What it means

The outer catch in getConnectionWithValidatedAuth. It catches anything thrown inside the try — including the 'Instance URL is missing' Error (253), getTokenDataFromValidatedSource Errors (255/256), and any jsforce.Connection constructor failure — and rewraps them as a QueryError with the original message. Because it wraps a QueryError thrown from inside, callers lose the original error class.

Source

Thrown at marketplace/plugins/salesforce/lib/index.ts:145

      if (!instanceUrl) {
        throw new Error('Instance URL is missing from token data in salesforce');
      }

      const oauth2 = new jsforce.OAuth2({
        clientId: client_id,
        clientSecret: client_secret,
        redirectUri: redirect_uri,
      });

      const conn = new jsforce.Connection({
        oauth2: oauth2,
        instanceUrl: instanceUrl,
        accessToken: accessToken,
      });
      return conn;
    } catch (error) {
      throw new QueryError('Connection Error in Salesforce with validated auth', error.message, {});
    }
  }

  private getTokenDataFromValidatedSource(sourceOptions: SourceOptions, context): any {
    if (sourceOptions.tokenData) {
      if (
        sourceOptions.multiple_auth_enabled &&
        Array.isArray(sourceOptions.tokenData) &&
        sourceOptions.tokenData.length > 0
      ) {
        const userTokenData = sourceOptions.tokenData.find((token) => token.user_id === context.user.id);
        if (!userTokenData) throw new Error('No token data for the particular UserId');
        if (userTokenData) return userTokenData;
      } else if (sourceOptions.tokenData) {
        return sourceOptions.tokenData;
      }
    }

View on GitHub (pinned to 20602a8e10)

Solutions

  1. Read the description — it carries the inner error's message (e.g., 'instance_url is missing').
  2. Re-authorize the datasource to repopulate all token fields.
  3. Verify getOAuthCredentials returns non-empty client_id/secret/redirect_uri (env vars set for tooljet_app type).
  4. Avoid wrapping QueryError-instances here; rethrow them to preserve the original code.

Example fix

// before
} catch (error) {
  throw new QueryError('Connection Error in Salesforce with validated auth', error.message, {});
}

// after: preserve typed errors
} catch (error) {
  if (error instanceof QueryError) throw error;
  throw new QueryError('Connection Error in Salesforce with validated auth', error.message, { cause: error.message });
}
Defensive patterns

Strategy: try-catch

Validate before calling

function validateMultiUserAuthInputs(sourceOptions: any, context: any): void {
  if (!context?.user?.id) throw new Error('context.user.id required');
  if (!sourceOptions?.tokenData) throw new Error('tokenData required for multi-user auth');
}

Type guard

import { QueryError } from '@tooljet-marketplace/common';
function isQueryError(e: any): e is QueryError {
  return e instanceof QueryError;
}

Try / catch

try {
  conn = await plugin.getConnectionWithValidatedAuth(sourceOptions, queryOptions, context);
} catch (e) {
  if (e instanceof QueryError && /instance_url|token data/i.test(e.description)) {
    return { status: 'needs_reconnect', reason: e.description };
  }
  throw e;
}

Prevention

When it happens

Trigger: Any failure constructing a jsforce.Connection for multi-user OAuth: missing instance_url, missing token data, invalid clientId/secret passed to OAuth2, jsforce throwing on bad arguments.

Common situations: Multi-user OAuth path enabled but per-user token data is incomplete. Connected app credentials changed. jsforce version incompatibility throwing in the constructor.

Related errors


AI-assisted analysis of ToolJet/ToolJet@20602a8e10 (2026-08-13). Data as JSON: /api/errors/02e5d9a06387f281. Report an issue: GitHub.