Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Connection

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.setApiVersion("42.0");
connection.query('SELECT Name from Account');

Hierarchy

  • Connection
    • Connection

Index

Properties

accessToken

accessToken: string

analytics

analytics: Analytics

apex

apex: Apex

bulk

bulk: Bulk

cache

cache: Cache

chatter

chatter: Chatter

describe$

describe$: function

Type declaration

    • (type: string, callback?: undefined | function): DescribeSObjectResult
    • Returns a value from the cache if it exists, otherwise calls Connection.describe

      Parameters

      • type: string
      • Optional callback: undefined | function

      Returns DescribeSObjectResult

describeGlobal$

describeGlobal$: function

Type declaration

    • (callback?: undefined | function): DescribeGlobalResult
    • Returns a value from the cache if it exists, otherwise calls Connection.describeGlobal

      Parameters

      • Optional callback: undefined | function

      Returns DescribeGlobalResult

instanceUrl

instanceUrl: string

metadata

metadata: Metadata

oauth2

oauth2: OAuth2

streaming

streaming: Streaming

tooling

tooling: Tooling

Tooling api reference.

version

version: string

Static defaultMaxListeners

defaultMaxListeners: number

Methods

_baseUrl

  • _baseUrl(): string
  • Returns string

addListener

  • addListener(event: string | symbol, listener: function): this
  • Parameters

    • event: string | symbol
    • listener: function
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

authorize

  • authorize(code: string, callback?: undefined | function): Promise<UserInfo>
  • Parameters

    • code: string
    • Optional callback: undefined | function

    Returns Promise<UserInfo>

autoFetchQuery

  • autoFetchQuery<T>(soql: string, options?: ExecuteOptions): Promise<QueryResult<T>>
  • 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

    Parameters

    • soql: string

      The SOQL string.

    • Default value options: ExecuteOptions = {}

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

    Returns Promise<QueryResult<T>>

baseUrl

  • baseUrl(): string
  • The Force API base url for the instance.

    Returns string

create

  • create<T>(type: string, records: Record<T> | Array<Record<T>>, options?: RestApiOptions, callback?: undefined | function): Promise<SuccessResult | ErrorResult | (SuccessResult | ErrorResult)[]>
  • Type parameters

    • T

    Parameters

    • type: string
    • records: Record<T> | Array<Record<T>>
    • Optional options: RestApiOptions
    • Optional callback: undefined | function

    Returns Promise<SuccessResult | ErrorResult | (SuccessResult | ErrorResult)[]>

del

  • del<T>(type: string, ids: string | string[], options?: RestApiOptions, callback?: undefined | function): Promise<SuccessResult | ErrorResult | (SuccessResult | ErrorResult)[]>
  • Type parameters

    • T

    Parameters

    • type: string
    • ids: string | string[]
    • Optional options: RestApiOptions
    • Optional callback: undefined | function

    Returns Promise<SuccessResult | ErrorResult | (SuccessResult | ErrorResult)[]>

delete

  • delete<T>(type: string, ids: string | string[], options?: RestApiOptions, callback?: undefined | function): Promise<SuccessResult | ErrorResult | (SuccessResult | ErrorResult)[]>
  • Type parameters

    • T

    Parameters

    • type: string
    • ids: string | string[]
    • Optional options: RestApiOptions
    • Optional callback: undefined | function

    Returns Promise<SuccessResult | ErrorResult | (SuccessResult | ErrorResult)[]>

describe

  • describe(type: string, callback?: undefined | function): Promise<DescribeSObjectResult>
  • Parameters

    • type: string
    • Optional callback: undefined | function

    Returns Promise<DescribeSObjectResult>

describeGlobal

  • describeGlobal<T>(callback?: undefined | function): Promise<DescribeGlobalResult>
  • Type parameters

    • T

    Parameters

    • Optional callback: undefined | function

    Returns Promise<DescribeGlobalResult>

destroy

  • destroy<T>(type: string, ids: string | string[], options?: RestApiOptions, callback?: undefined | function): Promise<SuccessResult | ErrorResult | (SuccessResult | ErrorResult)[]>
  • Type parameters

    • T

    Parameters

    • type: string
    • ids: string | string[]
    • Optional options: RestApiOptions
    • Optional callback: undefined | function

    Returns Promise<SuccessResult | ErrorResult | (SuccessResult | ErrorResult)[]>

emit

  • emit(event: string | symbol, ...args: any[]): boolean
  • Parameters

    • event: string | symbol
    • Rest ...args: any[]

    Returns boolean

eventNames

  • eventNames(): Array<string | symbol>
  • Returns Array<string | symbol>

getApiVersion

  • getApiVersion(): string
  • Get the API version used for all connection requests.

    Returns string

getAuthInfoFields

getConnectionOptions

getMaxListeners

  • getMaxListeners(): number
  • Returns number

getUsername

  • getUsername(): Optional<string>
  • Getter for the username of the Salesforce Org.

    Returns Optional<string>

init

  • init(): Promise<void>

initialize

  • Parameters

    Returns void

insert

  • insert<T>(type: string, records: Record<T> | Array<Record<T>>, options?: RestApiOptions, callback?: undefined | function): Promise<SuccessResult | ErrorResult | (SuccessResult | ErrorResult)[]>
  • Type parameters

    • T

    Parameters

    • type: string
    • records: Record<T> | Array<Record<T>>
    • Optional options: RestApiOptions
    • Optional callback: undefined | function

    Returns Promise<SuccessResult | ErrorResult | (SuccessResult | ErrorResult)[]>

isUsingAccessToken

  • isUsingAccessToken(): boolean
  • Returns true if this connection is using access token auth.

    Returns boolean

limits

  • limits(callback?: undefined | function): Promise<LimitsInfo>
  • Parameters

    • Optional callback: undefined | function

    Returns Promise<LimitsInfo>

listenerCount

  • listenerCount(type: string | symbol): number
  • Parameters

    • type: string | symbol

    Returns number

listeners

  • listeners(event: string | symbol): Function[]
  • Parameters

    • event: string | symbol

    Returns Function[]

login

  • login(user: string, password: string, callback?: undefined | function): Promise<UserInfo>
  • Parameters

    • user: string
    • password: string
    • Optional callback: undefined | function

    Returns Promise<UserInfo>

loginByOAuth2

  • loginByOAuth2(user: string, password: string, callback?: undefined | function): Promise<UserInfo>
  • Parameters

    • user: string
    • password: string
    • Optional callback: undefined | function

    Returns Promise<UserInfo>

loginBySoap

  • loginBySoap(user: string, password: string, callback?: undefined | function): Promise<UserInfo>
  • Parameters

    • user: string
    • password: string
    • Optional callback: undefined | function

    Returns Promise<UserInfo>

logout

  • logout(revoke: boolean, callback?: undefined | function): Promise<void>
  • logout(callback?: undefined | function): Promise<void>
  • Parameters

    • revoke: boolean
    • Optional callback: undefined | function

    Returns Promise<void>

  • Parameters

    • Optional callback: undefined | function

    Returns Promise<void>

logoutByOAuth2

  • logoutByOAuth2(revoke: boolean, callback?: undefined | function): Promise<void>
  • logoutByOAuth2(callback?: undefined | function): Promise<void>
  • Parameters

    • revoke: boolean
    • Optional callback: undefined | function

    Returns Promise<void>

  • Parameters

    • Optional callback: undefined | function

    Returns Promise<void>

logoutBySoap

  • logoutBySoap(revoke: boolean, callback?: undefined | function): Promise<void>
  • logoutBySoap(callback?: undefined | function): Promise<void>
  • Parameters

    • revoke: boolean
    • Optional callback: undefined | function

    Returns Promise<void>

  • Parameters

    • Optional callback: undefined | function

    Returns Promise<void>

normalizeUrl

  • normalizeUrl(url: string): string
  • Normalize a Salesforce url to include a instance information.

    Parameters

    • url: string

      Partial url.

    Returns string

off

  • off(event: string | symbol, listener: function): this
  • Parameters

    • event: string | symbol
    • listener: function
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

on

  • on(event: string | symbol, listener: function): this
  • Parameters

    • event: string | symbol
    • listener: function
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

once

  • once(event: string | symbol, listener: function): this
  • Parameters

    • event: string | symbol
    • listener: function
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

prependListener

  • prependListener(event: string | symbol, listener: function): this
  • Parameters

    • event: string | symbol
    • listener: function
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

prependOnceListener

  • prependOnceListener(event: string | symbol, listener: function): this
  • Parameters

    • event: string | symbol
    • listener: function
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

query

  • query<T>(soql: string, options?: ExecuteOptions, callback?: undefined | function): Query<QueryResult<T>>
  • Type parameters

    • T

    Parameters

    • soql: string
    • Optional options: ExecuteOptions
    • Optional callback: undefined | function

    Returns Query<QueryResult<T>>

queryAll

  • queryAll<T>(soql: string, options?: undefined | object, callback?: undefined | function): Query<QueryResult<T>>
  • Type parameters

    • T

    Parameters

    • soql: string
    • Optional options: undefined | object
    • Optional callback: undefined | function

    Returns Query<QueryResult<T>>

queryMore

  • queryMore<T>(locator: string, options?: ExecuteOptions, callback?: undefined | function): Promise<QueryResult<T>>
  • Type parameters

    • T

    Parameters

    • locator: string
    • Optional options: ExecuteOptions
    • Optional callback: undefined | function

    Returns Promise<QueryResult<T>>

rawListeners

  • rawListeners(event: string | symbol): Function[]
  • Parameters

    • event: string | symbol

    Returns Function[]

removeAllListeners

  • removeAllListeners(event?: string | symbol): this
  • Parameters

    • Optional event: string | symbol

    Returns this

removeListener

  • removeListener(event: string | symbol, listener: function): this
  • Parameters

    • event: string | symbol
    • listener: function
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

request

  • request(request: RequestInfo | string, options?: JsonMap): Promise<JsonCollection>
  • Send REST API request with given HTTP request info, with connected session information and SFDX headers.

    Parameters

    • request: RequestInfo | string

      HTTP request object or URL to GET request.

    • Optional options: JsonMap

      HTTP API request options.

    Returns Promise<JsonCollection>

requestRaw

  • requestRaw(request: RequestInfo): Promise<JsonMap>
  • Send REST API request with given HTTP request info, with connected session information and SFDX headers. This method returns a raw http response which includes a response body and statusCode.

    Parameters

    • request: RequestInfo

      HTTP request object or URL to GET request.

    Returns Promise<JsonMap>

retrieve

  • retrieve<T>(type: string, ids: string | string[], options?: RestApiOptions, callback?: undefined | function): Promise<object & T | (object & T)[]>
  • Type parameters

    • T

    Parameters

    • type: string
    • ids: string | string[]
    • Optional options: RestApiOptions
    • Optional callback: undefined | function

    Returns Promise<object & T | (object & T)[]>

retrieveMaxApiVersion

  • retrieveMaxApiVersion(): Promise<string>
  • Retrieves the highest api version that is supported by the target server instance.

    Returns Promise<string>

setApiVersion

  • setApiVersion(version: string): void
  • Set the API version for all connection requests.

    Throws SfdxError{ name: 'IncorrectAPIVersion' } Incorrect API version.

    Parameters

    • version: string

      The API version.

    Returns void

setMaxListeners

  • setMaxListeners(n: number): this
  • Parameters

    • n: number

    Returns this

sobject

  • sobject<T>(resource: string): SObject<T>
  • Type parameters

    • T

    Parameters

    • resource: string

    Returns SObject<T>

update

  • update<T>(type: string, records: Record<T> | Array<Record<T>>, options?: RestApiOptions, callback?: undefined | function): Promise<SuccessResult | ErrorResult | (SuccessResult | ErrorResult)[]>
  • Type parameters

    • T

    Parameters

    • type: string
    • records: Record<T> | Array<Record<T>>
    • Optional options: RestApiOptions
    • Optional callback: undefined | function

    Returns Promise<SuccessResult | ErrorResult | (SuccessResult | ErrorResult)[]>

upsert

  • upsert<T>(type: string, records: Record<T> | Array<Record<T>>, extIdField: string, options?: RestApiOptions, callback?: undefined | function): Promise<SuccessResult | ErrorResult | (SuccessResult | ErrorResult)[]>
  • Type parameters

    • T

    Parameters

    • type: string
    • records: Record<T> | Array<Record<T>>
    • extIdField: string
    • Optional options: RestApiOptions
    • Optional callback: undefined | function

    Returns Promise<SuccessResult | ErrorResult | (SuccessResult | ErrorResult)[]>

useLatestApiVersion

  • useLatestApiVersion(): Promise<void>
  • Use the latest API version available on this.instanceUrl.

    Returns Promise<void>

Static create

  • Creates an instance of a Connection. Performs additional async initializations.

    Parameters

    • this: object
    • options: Options

      Constructor options.

    Returns Promise<Connection>

Static listenerCount

  • listenerCount(emitter: EventEmitter, event: string | symbol): number
  • deprecated

    since v4.0.0

    Parameters

    • emitter: EventEmitter
    • event: string | symbol

    Returns number