Options
All
  • Public
  • Public/Protected
  • All
Menu

Handles connections and requests to Salesforce Orgs.

extends

jsforce.Connection

example

// Uses latest API version const connection = await Connection.create(await AuthInfo.create(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

Constructors

constructor

  • Parameters

    • options: ConnectionOptions
    • authInfo: AuthInfo
    • Optional logger: Logger

    Returns Connection

Properties

accessToken

accessToken: string

analytics

analytics: Analytics

bulk

bulk: Bulk

chatter

chatter: Chatter

instanceUrl

instanceUrl: string

metadata

metadata: Metadata

oauth2

oauth2: OAuth2

streaming

streaming: Streaming

tooling

tooling: Tooling

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
  • Returns string

    The Force API base url for the instance.

create

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

    • T

    Parameters

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

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

del

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

    • T

    Parameters

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

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

delete

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

    • T

    Parameters

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

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

describe

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

    • T

    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?: Object, callback?: undefined | function): Promise<SuccessResult | ErrorResult | (SuccessResult | ErrorResult)[]>
  • Type parameters

    • T

    Parameters

    • type: string
    • ids: string | string[]
    • Optional options: Object
    • 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

  • Getter for the AuthInfo

    Returns AuthFields

    A cloned authInfo.

getConnectionOptions

getMaxListeners

  • getMaxListeners(): number
  • Returns number

getUsername

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

    Returns Optional<string>

initialize

  • Parameters

    Returns void

insert

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

    • T

    Parameters

    • type: string
    • records: Record<T> | Array<Record<T>>
    • Optional options: Object
    • 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

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(callback?: undefined | function): Promise<void>
  • Parameters

    • Optional callback: undefined | function

    Returns Promise<void>

logoutByOAuth2

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

    • Optional callback: undefined | function

    Returns Promise<void>

logoutBySoap

  • logoutBySoap(callback?: undefined | function): 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.

    override

    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.

    override

    Parameters

    • request: RequestInfo

      HTTP request object or URL to GET request.

    Returns Promise<JsonMap>

    The request Promise.

retrieve

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

    • T

    Parameters

    • type: string
    • ids: string | string[]
    • Optional options: Object
    • 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>

    The max API version number. i.e 46.0

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?: Object, callback?: undefined | function): Promise<SuccessResult | ErrorResult | (SuccessResult | ErrorResult)[]>
  • Type parameters

    • T

    Parameters

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

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

upsert

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

    • T

    Parameters

    • type: string
    • records: Record<T> | Array<Record<T>>
    • extIdField: string
    • Optional options: Object
    • 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

  • Create and return a connection to an org using authentication info. The returned connection uses the latest API version available on the server unless the apiVersion config value is set.

    Parameters

    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