As W2 grows and matures manual processes become bottlenecks that slow the business down. We recently started a project to automate some of these processes so we can free people up and use their creativity on what matters. All this put us on a collision course with every developer’s nightmare, Salesforce.
Salesforce is a very important to us. But that doesnโt mean itโs not big and scary! Integrating with it can be very daunting when you start reading about Lightning and Apex.
This post is to demonstrate an alternative way of integrating with Salesforce using Azure Logic Apps. Weโre going to use the scenario of when an Account is created on Salesforce, we want to set up some configuration inside our platform. For this we need the Name and Id of the Salesforce Account.
The Salesforce way
To make this a fair comparison weโre first going to go through what it takes to do tackle the scenario in Salesforce. The scenario is a simple one, we should be able to just setup a webhook for whenever new Accounts are created. But, Salesforce doesn’t natively support web hooks. To get our web hook working we must dive deeper into the Salesforce ecosystem.
There are two steps to getting our webhook working, first we need to create a process using the Lightning Process Builder.
The Process builder allows us to trigger actions when a new Account is created. It sounds like the complete solution but annoyingly the Process Builder does not have a Http callout as a native action. To do this we must dive deeper into Salesforce again in step two and write a custom Apex class.
The Process Builder can be found in the Startup menu of Salesforce. Hereโs our process triggered by an Account being added:
The Process Builder is based on a traditional process flow diagram where the process starts at the top and flows down. The builder requires you to have conditionals in the process which is why we have one in the process above, even though itโs set to always be true. We call our Apex class in the Immediate Actions part of the process, here’s a more detailed view:
As you can see weโre missing the Account Name from the variables weโre sending to the class. This is because itโs not available in the process builder which means weโll have to make a Salesforce call later to retrieve it.
Hereโs the actual Apex class weโre using to post the Account Id to our systems:
public class NewClient{
@InvocableMethod(label='Create New Client' description='Creates a new Client in the W2 platform')
public static void CreateClient(List<ID> ids){
NewClient.Create(ids);
}
@future (callout=true)
public static void Create(List<ID> ids){
for (String id : ids){
HttpRequest req = new HttpRequest();
req.setEndpoint('https://endpoint.com');
req.setMethod('POST');
req.setBody('{"ID": "' + id + '"}');
req.setHeader('Content-Type', 'application/json');
Http http = new Http();
HTTPResponse res = http.send(req);
System.debug(res.getBody());
}
}
}
Apex isnโt that scary really if youโre familiar with C# or Java. Thereโs just a few gotchas with the attributes that you need to be careful. You need an Invocable attribute for methods you wish to call from the process builder and a future attribute for the method that makes the callout. It’s worth pointing out that as this is just a demo the class above is missing some important features such as Authentication and Tests.
So even though thereโs still a lot to do to make this solution Production ready, it does do what we need and fulfils our requirements. The downside of this approach is obviously that we need to know a lot about how Salesforce works internally which takes a lot of time to learn. It also becomes painful when we need to start tracking other Salesforce objects and need to replicate all of this.
Logic Apps to the rescue
Logic Apps are awesome. Theyโre Azureโs no code serverless solution for making business workflows and integrations. The power of Logic Apps come from its connectors. It has built in connectors for most Azure services as well as a lot of non-Azure services such as Dropbox, Ethereum, Gmail and Salesforce.
With the built-in connectors we can create the same solution as we did in Salesforce with one app:
The process starts with a Salesforce trigger that activates when a record is changed in Salesforce. Unlike the Salesforce process builder, we can make http calls straight from the Logic App so we can use the built in Http action instead of setting up a custom one. Itโs also a lot cleaner that you are not forced to have conditionals you donโt need in the process.
Hereโs the details of the Salesforce trigger:
The Salesforce trigger allows you to track 100โs of objects in Salesforce, as per our scenario its setup to trigger on new Accounts. You can also specify how often the trigger polls for new objects.
Using the dynamic content feature of Logic Apps we can use the new Salesforce account in the Http action:
Unlike the Salesforce process builder, we have access to the entire Account object. This means that we can send the Name of the Account straight to our platform and not have to do a second call to get it.
Polling is a scary word that is usually associated with high cost. In the old Log Apps pricing model this would have been correct. But they updated the model a few years ago and made it a flat fee of ยฃ0.000019 per execution which reduced the cost significantly. Because each poll of Salesforce is classified as an execution is becomes very cheap, check out the table:
Polling Frequency | Cost Per Month |
Every 1 minute | ยฃ4.1172 |
Every 5 minute | ยฃ0.82344 |
Every 30 minute | ยฃ0.13724 |
Every 60 minute | ยฃ0.06862 |
Of course this is just the costings for the polling, every action after that is classed as another execution. But at ยฃ0.000019 per execution itโs not even pinching pennies!
Comparison
I donโt think I need to write an extensive conclusion. Logic apps are designed to simplify integrations to third party services. Theyโre very quick to setup, the graphical editor means you donโt need to learn any new languages or frameworks. Basically, letting Azure handle the Salesforce integration saves a lot of time and doesnโt break the bank. We Like Logic Apps ๐