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$: { clear: any }

Type declaration

    • (type: string | DescribeSObjectOptions, callback?: undefined | ((err: Error, result: DescribeSObjectResult) => void)): DescribeSObjectResult
    • Returns a value from the cache if it exists, otherwise calls Connection.describe

      Parameters

      • type: string | DescribeSObjectOptions
      • Optional callback: undefined | ((err: Error, result: DescribeSObjectResult) => void)

      Returns DescribeSObjectResult

  • clear: function
    • clear(): void
    • Returns void

describeGlobal$

describeGlobal$: { clear: any }

Type declaration

    • (callback?: undefined | ((err: Error, result: DescribeGlobalResult) => void)): DescribeGlobalResult
    • Returns a value from the cache if it exists, otherwise calls Connection.describeGlobal

      Parameters

      • Optional callback: undefined | ((err: Error, result: DescribeGlobalResult) => void)

      Returns DescribeGlobalResult

  • clear: function
    • clear(): void
    • Returns void

instanceUrl

instanceUrl: string

metadata

metadata: Metadata

oauth2

oauth2: OAuth2

Optional refreshToken

refreshToken: undefined | string

soap

soap: SoapApi

streaming

streaming: Streaming

tooling

tooling: Tooling

Tooling api reference.

Optional userInfo

userInfo: UserInfo

version

version: string

Methods

_baseUrl

  • _baseUrl(): string
  • Returns string

addListener

  • addListener(event: string | symbol, listener: (...args: any[]) => void): this
  • Parameters

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

          • Rest ...args: any[]

          Returns void

    Returns this

authorize

  • authorize(code: string, callback?: undefined | ((err: Error, res: UserInfo) => void)): Promise<UserInfo>
  • Parameters

    • code: string
    • Optional callback: undefined | ((err: Error, res: UserInfo) => void)

    Returns Promise<UserInfo>

autoFetchQuery

  • autoFetchQuery<T>(soql: string, executeOptions?: 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 executeOptions: ExecuteOptions = {}

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

    Returns Promise<QueryResult<T>>

baseUrl

  • baseUrl(): string

batchDescribe

  • batchDescribe(options: BatchDescribeSObjectOptions, callback?: undefined | ((err: Error, result: DescribeSObjectResult[]) => void)): Promise<DescribeSObjectResult[]>
  • Parameters

    • options: BatchDescribeSObjectOptions
    • Optional callback: undefined | ((err: Error, result: DescribeSObjectResult[]) => void)

    Returns Promise<DescribeSObjectResult[]>

create

  • create<T>(type: string, records: Record<T> | Array<Record<T>>, options?: RestApiOptions, callback?: undefined | ((err: Error, result: RecordResult | RecordResult[]) => void)): Promise<RecordResult | RecordResult[]>
  • Type parameters

    • T

    Parameters

    • type: string
    • records: Record<T> | Array<Record<T>>
    • Optional options: RestApiOptions
    • Optional callback: undefined | ((err: Error, result: RecordResult | RecordResult[]) => void)

    Returns Promise<RecordResult | RecordResult[]>

del

  • del<T>(type: string, ids: string | string[], options?: RestApiOptions, callback?: undefined | ((err: Error, result: RecordResult | RecordResult[]) => void)): Promise<RecordResult | RecordResult[]>
  • Type parameters

    • T

    Parameters

    • type: string
    • ids: string | string[]
    • Optional options: RestApiOptions
    • Optional callback: undefined | ((err: Error, result: RecordResult | RecordResult[]) => void)

    Returns Promise<RecordResult | RecordResult[]>

delete

  • delete<T>(type: string, ids: string | string[], options?: RestApiOptions, callback?: undefined | ((err: Error, result: RecordResult | RecordResult[]) => void)): Promise<RecordResult | RecordResult[]>
  • Type parameters

    • T

    Parameters

    • type: string
    • ids: string | string[]
    • Optional options: RestApiOptions
    • Optional callback: undefined | ((err: Error, result: RecordResult | RecordResult[]) => void)

    Returns Promise<RecordResult | RecordResult[]>

deploy

  • deploy(zipInput: Buffer, options: DeployOptionsWithRest, callback?: Callback<AsyncResult>): Promise<DeployResultLocator<AsyncResult>>
  • TODO: This should be moved into JSForce V2 once ready this is only a temporary solution to support both REST and SOAP APIs

    deploy a zipped buffer from the SDRL with REST or SOAP

    Parameters

    • zipInput: Buffer

      data to deploy

    • options: DeployOptionsWithRest

      JSForce deploy options + a boolean for rest

    • Optional callback: Callback<AsyncResult>

    Returns Promise<DeployResultLocator<AsyncResult>>

deployRecentValidation

  • TODO: This should be moved into JSForce V2 once ready this is only a temporary solution to support both REST and SOAP APIs

    Will deploy a recently validated deploy request

    Parameters

    Returns Promise<JsonCollection>

describe

  • describe(type: string | DescribeSObjectOptions, callback?: undefined | ((err: Error, result: DescribeSObjectResult) => void)): Promise<DescribeSObjectResult>
  • Parameters

    • type: string | DescribeSObjectOptions
    • Optional callback: undefined | ((err: Error, result: DescribeSObjectResult) => void)

    Returns Promise<DescribeSObjectResult>

describeGlobal

  • describeGlobal<T>(callback?: undefined | ((err: Error, result: DescribeGlobalResult) => void)): Promise<DescribeGlobalResult>
  • Type parameters

    • T

    Parameters

    • Optional callback: undefined | ((err: Error, result: DescribeGlobalResult) => void)

    Returns Promise<DescribeGlobalResult>

destroy

  • destroy<T>(type: string, ids: string | string[], options?: RestApiOptions, callback?: undefined | ((err: Error, result: RecordResult | RecordResult[]) => void)): Promise<RecordResult | RecordResult[]>
  • Type parameters

    • T

    Parameters

    • type: string
    • ids: string | string[]
    • Optional options: RestApiOptions
    • Optional callback: undefined | ((err: Error, result: RecordResult | RecordResult[]) => void)

    Returns Promise<RecordResult | RecordResult[]>

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

getAuthInfoFields

getConnectionOptions

getMaxListeners

  • getMaxListeners(): number

getUsername

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

    Returns Optional<string>

identity

  • identity(callback?: undefined | ((err: Error, res: IdentityInfo) => void)): Promise<IdentityInfo>
  • Parameters

    • Optional callback: undefined | ((err: Error, res: IdentityInfo) => void)

    Returns Promise<IdentityInfo>

init

  • init(): Promise<void>

initialize

insert

  • insert<T>(type: string, records: Record<T> | Array<Record<T>>, options?: RestApiOptions, callback?: undefined | ((err: Error, result: RecordResult | RecordResult[]) => void)): Promise<RecordResult | RecordResult[]>
  • Type parameters

    • T

    Parameters

    • type: string
    • records: Record<T> | Array<Record<T>>
    • Optional options: RestApiOptions
    • Optional callback: undefined | ((err: Error, result: RecordResult | RecordResult[]) => void)

    Returns Promise<RecordResult | RecordResult[]>

isResolvable

  • isResolvable(): Promise<boolean>
  • Verify that instance has a reachable DNS entry, otherwise will throw error

    Returns Promise<boolean>

isUsingAccessToken

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

    Returns boolean

limits

  • limits(callback?: undefined | ((err: Error, res: undefined) => void)): Promise<LimitsInfo>
  • Parameters

    • Optional callback: undefined | ((err: Error, res: undefined) => void)

    Returns Promise<LimitsInfo>

listenerCount

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

    • event: string | symbol

    Returns number

listeners

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

    • event: string | symbol

    Returns Function[]

login

  • login(user: string, password: string, callback?: undefined | ((err: Error, res: UserInfo) => void)): Promise<UserInfo>
  • Parameters

    • user: string
    • password: string
    • Optional callback: undefined | ((err: Error, res: UserInfo) => void)

    Returns Promise<UserInfo>

loginByOAuth2

  • loginByOAuth2(user: string, password: string, callback?: undefined | ((err: Error, res: UserInfo) => void)): Promise<UserInfo>
  • Parameters

    • user: string
    • password: string
    • Optional callback: undefined | ((err: Error, res: UserInfo) => void)

    Returns Promise<UserInfo>

loginBySoap

  • loginBySoap(user: string, password: string, callback?: undefined | ((err: Error, res: UserInfo) => void)): Promise<UserInfo>
  • Parameters

    • user: string
    • password: string
    • Optional callback: undefined | ((err: Error, res: UserInfo) => void)

    Returns Promise<UserInfo>

logout

  • logout(revoke: boolean, callback?: undefined | ((err: Error, res: undefined) => void)): Promise<void>
  • logout(callback?: undefined | ((err: Error, res: undefined) => void)): Promise<void>
  • Parameters

    • revoke: boolean
    • Optional callback: undefined | ((err: Error, res: undefined) => void)

    Returns Promise<void>

  • Parameters

    • Optional callback: undefined | ((err: Error, res: undefined) => void)

    Returns Promise<void>

logoutByOAuth2

  • logoutByOAuth2(revoke: boolean, callback?: undefined | ((err: Error, res: undefined) => void)): Promise<void>
  • logoutByOAuth2(callback?: undefined | ((err: Error, res: undefined) => void)): Promise<void>
  • Parameters

    • revoke: boolean
    • Optional callback: undefined | ((err: Error, res: undefined) => void)

    Returns Promise<void>

  • Parameters

    • Optional callback: undefined | ((err: Error, res: undefined) => void)

    Returns Promise<void>

logoutBySoap

  • logoutBySoap(revoke: boolean, callback?: undefined | ((err: Error, res: undefined) => void)): Promise<void>
  • logoutBySoap(callback?: undefined | ((err: Error, res: undefined) => void)): Promise<void>
  • Parameters

    • revoke: boolean
    • Optional callback: undefined | ((err: Error, res: undefined) => void)

    Returns Promise<void>

  • Parameters

    • Optional callback: undefined | ((err: Error, res: undefined) => void)

    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: (...args: any[]) => void): this
  • Parameters

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

          • Rest ...args: any[]

          Returns void

    Returns this

on

  • on(event: string | symbol, listener: (...args: any[]) => void): this
  • Parameters

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

          • Rest ...args: any[]

          Returns void

    Returns this

once

  • once(event: string | symbol, listener: (...args: any[]) => void): this
  • Parameters

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

          • Rest ...args: any[]

          Returns void

    Returns this

prependListener

  • prependListener(event: string | symbol, listener: (...args: any[]) => void): this
  • Parameters

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

          • Rest ...args: any[]

          Returns void

    Returns this

prependOnceListener

  • prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this
  • Parameters

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

          • Rest ...args: any[]

          Returns void

    Returns this

query

  • query<T>(soql: string, options?: ExecuteOptions, callback?: undefined | ((err: Error, result: QueryResult<T>) => void)): Query<QueryResult<T>>
  • Type parameters

    • T

    Parameters

    • soql: string
    • Optional options: ExecuteOptions
    • Optional callback: undefined | ((err: Error, result: QueryResult<T>) => void)

    Returns Query<QueryResult<T>>

queryAll

  • queryAll<T>(soql: string, options?: undefined | object, callback?: undefined | ((err: Error, result: QueryResult<T>) => void)): Query<QueryResult<T>>
  • Type parameters

    • T

    Parameters

    • soql: string
    • Optional options: undefined | object
    • Optional callback: undefined | ((err: Error, result: QueryResult<T>) => void)

    Returns Query<QueryResult<T>>

queryMore

  • queryMore<T>(locator: string, options?: ExecuteOptions, callback?: undefined | ((err: Error, result: QueryResult<T>) => void)): Promise<QueryResult<T>>
  • Type parameters

    • T

    Parameters

    • locator: string
    • Optional options: ExecuteOptions
    • Optional callback: undefined | ((err: Error, result: QueryResult<T>) => void)

    Returns Promise<QueryResult<T>>

rawListeners

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

    • event: string | symbol

    Returns Function[]

recent

  • recent(callback?: undefined | ((err: Error, result: RecordResult[]) => void)): Promise<RecordResult[]>
  • recent(param: number | string, callback?: undefined | ((err: Error, result: RecordResult[]) => void)): Promise<RecordResult[]>
  • recent(type: string, limit: number, callback?: undefined | ((err: Error, result: RecordResult[]) => void)): Promise<RecordResult[]>
  • Parameters

    • Optional callback: undefined | ((err: Error, result: RecordResult[]) => void)

    Returns Promise<RecordResult[]>

  • Parameters

    • param: number | string
    • Optional callback: undefined | ((err: Error, result: RecordResult[]) => void)

    Returns Promise<RecordResult[]>

  • Parameters

    • type: string
    • limit: number
    • Optional callback: undefined | ((err: Error, result: RecordResult[]) => void)

    Returns Promise<RecordResult[]>

removeAllListeners

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

    • Optional event: string | symbol

    Returns this

removeListener

  • removeListener(event: string | symbol, listener: (...args: any[]) => void): this
  • Parameters

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

          • Rest ...args: any[]

          Returns void

    Returns this

request

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

    Type parameters

    • T

    Parameters

    • request: RequestInfo | string

      HTTP request object or URL to GET request.

    • Optional options: JsonMap

      HTTP API request options.

    Returns Promise<T>

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 | ((err: Error, result: Record<T> | Array<Record<T>>) => void)): Promise<Record<T> | Array<Record<T>>>
  • Type parameters

    • T

    Parameters

    • type: string
    • ids: string | string[]
    • Optional options: RestApiOptions
    • Optional callback: undefined | ((err: Error, result: Record<T> | Array<Record<T>>) => void)

    Returns Promise<Record<T> | Array<Record<T>>>

retrieveMaxApiVersion

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

    Returns Promise<string>

search

  • search<T>(sosl: string, callback?: undefined | ((err: Error, result: SearchResult<T>) => void)): Promise<SearchResult<T>>
  • Type parameters

    • T

    Parameters

    • sosl: string
    • Optional callback: undefined | ((err: Error, result: SearchResult<T>) => void)

    Returns Promise<SearchResult<T>>

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

singleRecordQuery

  • 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

    Parameters

    • soql: string

      The SOQL string.

    • Default value options: SingleRecordQueryOptions = {choiceField: 'Name',}

      The query options.

    Returns Promise<T>

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 | ((err: Error, result: RecordResult | Array<Record<T>>) => void)): Promise<RecordResult | RecordResult[]>
  • update<T>(records: Record<T> | Array<Record<T>>, options?: RestApiOptions, callback?: undefined | ((err: Error, result: RecordResult | Array<Record<T>>) => void)): Promise<RecordResult | RecordResult[]>
  • Type parameters

    • T

    Parameters

    • type: string
    • records: Record<T> | Array<Record<T>>
    • Optional options: RestApiOptions
    • Optional callback: undefined | ((err: Error, result: RecordResult | Array<Record<T>>) => void)

    Returns Promise<RecordResult | RecordResult[]>

  • Type parameters

    • T

    Parameters

    • records: Record<T> | Array<Record<T>>
    • Optional options: RestApiOptions
    • Optional callback: undefined | ((err: Error, result: RecordResult | Array<Record<T>>) => void)

    Returns Promise<RecordResult | RecordResult[]>

upsert

  • upsert<T>(type: string, records: Record<T> | Array<Record<T>>, extIdField: string, options?: RestApiOptions, callback?: undefined | ((err: Error, result: RecordResult | RecordResult[]) => void)): Promise<RecordResult | RecordResult[]>
  • upsert<T>(records: Record<T> | Array<Record<T>>, extIdField: string, options?: RestApiOptions, callback?: undefined | ((err: Error, result: RecordResult | RecordResult[]) => void)): Promise<RecordResult | RecordResult[]>
  • Type parameters

    • T

    Parameters

    • type: string
    • records: Record<T> | Array<Record<T>>
    • extIdField: string
    • Optional options: RestApiOptions
    • Optional callback: undefined | ((err: Error, result: RecordResult | RecordResult[]) => void)

    Returns Promise<RecordResult | RecordResult[]>

  • Type parameters

    • T

    Parameters

    • records: Record<T> | Array<Record<T>>
    • extIdField: string
    • Optional options: RestApiOptions
    • Optional callback: undefined | ((err: Error, result: RecordResult | RecordResult[]) => void)

    Returns Promise<RecordResult | RecordResult[]>

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: {}
    • options: Options

      Constructor options.

    Returns Promise<Connection>