Use Azure Logic Apps to simplify Salesforce integrations

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 🙂 

Leave a Reply

Your email address will not be published.

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Scroll to Top