Defines a connection to a Salesforce org.

Hierarchy

  • SalesforceConnection

Properties

consumerKey: string

The consumer key of the Connected App used to connect.

disconnect: (() => Promise<void>)

Type declaration

    • (): Promise<void>
    • Closes the connection with the currently connected Salesforce org. Stored auth keys are expired and removed.

      Returns Promise<void>

getAuthTokens: (() => AuthTokenSet)

Type declaration

    • Retrieves the connection’s auth tokens from local storage.

      Returns

      An object containing the access and refresh tokens.

      Returns AuthTokenSet

orgUrl: string

The URL of the connected Salesforce org.

Methods

  • Executes a custom REST API request to the specified endpoint.

    Typically, every Salesforce REST API data endpoint must include the REST API version that is being requested. However, when calling the executeApiRequest function you can either explicitly set the REST API version to call or simply use "vXX.X" to default to the REST API version set by the API.

    For POST/PATCH requests, Content-Type header is set to "application/json" by default and so data parameter can simply be set to an object.

    Note: depending on which REST API endpoint you attempt to request, you may need to add additional OAuth scopes to your Connected App.

    Returns

    A SalesforceRestApiResponse response object containing the status code and response data (if provided). The data is expected to be of the given generic type, but this is not enforced.

    Throws

    ConnectionError Thrown if the connection object is no longer valid, for example if the session has been disconnected.

    Throws

    ParameterError Thrown if invalid function parameter values are detected.

    Throws

    RestApiError Thrown if an error occurs calling the Salesforce REST API.

    Type Parameters

    Parameters

    • apiEndpoint: string

      The relative Salesforce REST API endpoint being requested (e.g. /services/data/vXX.X/sobjects/Contact).

    • Optional httpMethod: HttpMethod

      The HTTP Method to use when making the request (defaults to GET).

    • Optional data: any

      Optional data to pass with the request (for POST/PATCH requests).

    • Optional headers: any

      Optional headers to include with the request. Important: do not attempt to set the Authorization header manually as the API will include it automatically (as long as includeAuthorization is not set to false).

    • Optional includeAuthorization: boolean

      Whether the Authorization header will be added automatically. Set this to false when making requests to endpoints that do not expect an Authorization header, such as the OAuth endpoints.

    Returns Promise<SalesforceRestApiResult<T>>

Generated using TypeDoc