Options
All
  • Public
  • Public/Protected
  • All
Menu

Defines a connection to a Salesforce org.

Hierarchy

  • SalesforceConnection

Index

Properties

consumerKey

consumerKey: string

The consumer key of the Connected App used to connect.

executeApiRequest

executeApiRequest: <T>(apiEndpoint: string, httpMethod?: HttpMethod, data?: any, headers?: any) => Promise<SalesforceRestApiResponse<T>>

Type declaration

    • 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.

      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

      • T

        An interface defining the expected data returned from Salesforce for the given query.

      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. Do not set the Authorization header as this will be added automatically.

      Returns Promise<SalesforceRestApiResponse<T>>

      A promise resolving to a 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.

getObjectById

getObjectById: <T>(id: string, objectType: T) => Promise<SalesforceObject<T> | null>

Type declaration

    • Retrieves the the Salesforce object with the given ID and type, including all field values.

      throws

      ConnectionError Thrown if there is a issue with the connection to Salesforce.

      throws

      ObjectDataError Thrown if an error occurs retrieving object data.

      throws

      ParameterError Thrown if invalid function parameter values are detected.

      Type parameters

      • T: string

        The type of the Salesforce object being retrieved (will be inferred from the objectType parameter).

      Parameters

      • id: string

        The ID of the Salesforce object to retrieve.

      • objectType: T

        The type of object being retrieved (e.g. Account/Contact/etc. Prefer SalesforceObjectType enum to string for known types).

      Returns Promise<SalesforceObject<T> | null>

      A promise resolving to the object with the requested ID, or null if it can not be found. If the objectType parameter is a known object type, a more detailed return type will be used that better describes the object (see SalesforceAccount, SalesforceContact, SalesforceOpportunity and SalesforceTask).

orgUrl

orgUrl: string

The URL of the connected Salesforce org.

search

search: (query: SalesforceSearchQuery) => Promise<SalesforceSearchResult[]>

Type declaration

    • (query: SalesforceSearchQuery): Promise<SalesforceSearchResult[]>
    • Executes a SOSL query that searches Account and Contact objects.

      If only text is provided, or emailAddress and/or phoneNumber is provided with text then the query will search all fields. If only emailAddress or phoneNumber is provided then the query will search email or phone number fields respectively.

      Optionally, provide a limit to restrict the number of search results returned (defaults to 10).

      throws

      ConnectionError Thrown if there is a issue with the connection to Salesforce.

      throws

      ParameterError Thrown if query parameter does not set at least one of the emailAddress, phoneNumber or text properties.

      throws

      SearchError Thrown if an error occurs executing the search.

      Parameters

      • query: SalesforceSearchQuery

        A {@link SalesforceSearchQuery} describing the search to be performed.

      Returns Promise<SalesforceSearchResult[]>

      A promise resolving to an array of {@link SalesforceSearchResult} which is a discriminated union of {@link SalesforceAccountSearchResult} and {@link SalesforceContactSearchResult}, with the discriminator being the objectType property.

Methods

disconnect

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

    Returns Promise<void>

Generated using TypeDoc