Handles connections and requests to Salesforce Orgs.

// Uses latest API version
const connection = await Connection.create({
authInfo: await AuthInfo.create({ username: 'myAdminUsername' })
connection.query('SELECT Name from Account');

// Use different API version
connection.query('SELECT Name from Account');

Type Parameters

  • S extends Schema = Schema


  • Connection<S>
    • Connection



  • Executes a query and auto-fetches (i.e., "queryMore") all results. This is especially useful with large query result sizes, such as over 2000 records. The default maximum fetch size is 10,000 records. Modify this via the options argument.

    Type Parameters

    • T extends Schema = S


    • soql: string

      The SOQL string.

    • queryOptions: Partial<QueryOptions & {
          tooling: boolean;
      }> = ...

      The query options. NOTE: the autoFetch option will always be true.

    Returns Promise<QueryResult<T>>

  • deploy a zipped buffer from the SDRL with REST or SOAP


    • zipInput: Buffer

      data to deploy

    • options: DeployOptionsWithRest

      JSForce deploy options + a boolean for rest

    Returns Promise<DeployResultLocator<AsyncResult & Schema>>

  • Get the API version used for all connection requests.

    Returns string

  • Getter for the username of the Salesforce Org.

    Returns Optional<string>

  • Verify that instance has a reachable DNS entry, otherwise will throw error

    Returns Promise<boolean>

  • Returns true if this connection is using access token auth.

    Returns boolean

  • Normalize a Salesforce url to include a instance information.


    • url: string

      Partial url.

    Returns string

  • Executes a get request on the baseUrl to force an auth refresh Useful for the raw methods (request, requestRaw) that use the accessToken directly and don't handle refreshes

    Returns Promise<void>

  • Send REST API request with given HTTP request info, with connected session information and SFDX headers.

    Type Parameters

    • R = unknown


    • request: string | HttpRequest

      HTTP request object or URL to GET request.

    • Optional options: JsonMap

      HTTP API request options.

    Returns StreamPromise<R>

  • Retrieves the highest api version that is supported by the target server instance.

    Returns Promise<string>

  • Set the API version for all connection requests.

    Throws SfError{ name: 'IncorrectAPIVersionError' } Incorrect API version.


    • version: string

      The API version.

    Returns void

  • Executes a query using either standard REST or Tooling API, returning a single record. Will throw if either zero records are found OR multiple records are found.

    Type Parameters

    • T extends Record


    Returns Promise<T>

  • Use the latest API version available on this.instanceUrl.

    Returns Promise<void>