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 Exchange
One 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
Learn how to send and receive JSON data and how to avoid potential problems you may encounter in the rest of my article here.
Stephen Bucholtz, Principal Engineer
Stephen Bucholtz has been a software engineer at Accusoft since 2005. He has spent most of his time there working on the PICTools SDK. More recently, he has branched out from the world of low-level toolkits to work on the OnTask web application. He is also responsible for the development and maintenance of Accusoft’s highly acclaimed mobile app: Cram. Since receiving his master’s degree in Computer Science from the University of Florida, Stephen has had a lengthy career working on everything from financial systems to embedded software for communications products. When Stephen is away from work, he can often be seen playing drums with various jazz groups around the Tampa Bay area.