These days, everything needs to be in the cloud. Salesforce has been on the forefront of cloud applications for over two decades. Others have followed suit and joined the future by making cloud based applications the norm. Accounting is no different and there is a multitude of possibilities already available online. To really benefit from these web-based applications, they need to be connected, so let’s try and connect our Salesforce Org to an external accounting web application.

 

Let’s dive right in

By connecting our Salesforce Org with an Accounting environment, we synchronize the sales and finance aspects of our business. This will give us the capabilities to closely monitor the financial data available and insert it back into Salesforce to optimize our sales and service teams. In this blog we will connect our Salesforce Org to an Exact Online (EOL) environment

 

Let’s get technical

Now let’s shift our gaze to the technical side. To let Salesforce access external web services and vice versa, a Public Site needs to be created. Salesforce sites enables you to create public websites and applications that are directly integrated with your Salesforce.com organization. To create the Public Site, navigate to the Sites tab through the Salesforce setup. Be sure to create a valid domain that matches your organization. 

For our purpose, we will call the site ‘Public API’ and leave all other fields as default values. 


Apex to the rescue

Unfortunately, this is where the clicking without coding ends. Exact Online will access our Public Site through a REST-call. To tell Salesforce what needs to happen when a REST-call is made to the Public Site, we need to use Apex. To make this work, we annotated our Apex class with the @RestResource annotation as shown in the picture below.

To use the Exact Online API we need to be authorized. EOL uses a combination of tokens that need to be used in HTTP REST-calls to their web service.

 

The authorization sequence

EOL uses two tokens: an access token and a refresh token. The access token is used to authorize our API calls, but it is not valid permanently. When it expires, we can use the refresh token to get a new one. So let’s get a refresh token from EOL.

First we have to create so-called API keys. To do this, navigate to the Register API-keys tab in your EOL environment and follow the provided steps. All that is needed, is a name for the key and a redirect URI. We want EOL to send the response to our REST Resource, so we input the address of the Public Site we created and add the URL set in our Resource. 

EOL then provides a Client Id and a Client Secret. These need to be used in a new Http-request to obtain a refresh token. Once we have the refresh token, we can obtain access tokens by making a Post Http-request containing the refresh token, the Client Id and the Client secret.


 

The package

At Cloud Innovation, we strive to work as fluent and efficient as possible. A lot of the code necessary to attain the tokens and keys can be used across different Salesforce Orgs. That’s why we have created a managed package unsurprisingly called Exact Online Connector (cieo). It contains all the code to automatically retrieve the information from EOL and persist the responses in a custom SObject called Authentication. 


As we’ve mentioned before, there are a number of codes, keys and tokens that need to be saved somewhere. That’s where the Authentication custom SObject comes into play. All information concerning the link with EOL like the Client Id, Client secret, redirect URL, tokens, errors and more are stored in a single record of the Authentication SObject. 

So how do we synchronize Salesforce records to and from EOL? As every org has different needs, a complete automatic synchronization would be impossible. The package does however supply Apex classes that lay all the groundwork. These classes can easily be extended to customize which fields need to be synchronized between Salesforce and EOL. 

All information about the Exact Online API can be found here.

 

Synchronization activated

Hurray! We can now easily import our Salesforce data into an accounting application and insert the financial data into our Salesforce Org. Together, the sales, service and finance data form a powerful tool to optimize and streamline your business. So get to it!