Communicating with External Systems in a Salesforce Application
Salesforce applications provide a way to easily extend the capabilities of the popular customer relationship management platform Salesforce. A Salesforce user can choose from thousands of apps that are available on the Salesforce App ExchangeOne common capability provided by Salesforce apps is the ability to communicate with external systems in order to extend the functionality of Salesforce. For example, the OnTask Salesforce app provides the ability to launch and monitor OnTask workflows directly in Salesforce.
As a Salesforce app developer, how does one incorporate communication with external systems into an app? Continue reading as we provide a brief introduction to this topic.
Calling REST API Endpoints via HTTP
Web-based services frequently expose their services via a REST API. HTTP is typically the protocol used to access these services.
Salesforce apps are developed using Apex, a strongly typed, object-oriented programming language. Apex allows integration with external REST Web services using callouts. Callouts allow communication with external systems via HTTP. Each callout request is associated with an HTTP method and an endpoint.In order to develop a callout, several different Apex classes are used. These classes are described below.
This class is used to initiate an HTTP message exchange and obtain the response. The method send() is used to send the message.
This class is used to create an HTTP request that can then be sent using the HTTP class. Various attributes of the HTTP request can be set, such as the method, endpoint, and header fields.
This class represents the response received from the HTTP class after a request has been sent. The class has methods for getting various parts of the response, such as getStatusCode() and getBody().
The following example involves calling an OnTask REST API endpoint. This endpoint retrieves the start form associated with a workflow model. The start form allows the user to provide input data when starting a workflow.
In this example, two functions are defined:
- sendGetWorkflowStartForm() – encapsulates the lowest level processing, which consists of constructing the HTTP request and sending the request
- getWorkflowStartForm() – calls the lower-level function and processes the response