Serverless integration with Salesforce using Kumologica
ab73863
Posted on April 5, 2021
Salesforce is a popular CRM platform used by many enterprises. Integration of salesforce modules with different enterprise systems are very common. There are multiple ways by which salesforce objects can be integrated .
- SOQL query (Pulling the records)
- Platform Events (Pushing the events)
- CDC (Pushing the events)
- OutboundMessages (Pushing the events using webhooks)
Most of the real time integrations with Salesforce works with PE(platform events), CDC and OutboundMessages. There are also solutions where SOQL query works in complementary with PE, CDC or OutboundMessages (Webhooks).
In this article we will see how to send a Salesforce outbound message to the target systems using Kumologica flow that runs on serverless infrastructure. For those who are new to Kumologica I would recommend to go through our articles and youtube videos to get an insight.
Concept
Before we begin let’s try to understand the working mechanism behind outbound messages in Salesforce.
OutboundMessages in salesforce is part of workflow in salesforce. The underlying mechanism is based on webhook notification. Whenever a change happens in any salesforce objects an associated outbound message is triggered by the workflow rule. The change can be an insert, update or a delete of an salesforce object. The outbound message is configured with a HTTP post endpoint. Salesforce outbound message will invoke the endpoint to send a SOAP payload having the appropriate object fields (eg : Case, Contact, etc).
Use Case
In this use case we will be using the Salesforce contact object. Whenever a new contact is created in Salesforce an event is triggered which will be sent to the target system by Kumologica flow. Here the target system is Amazon SQS queue.
The HTTP endpoint implementation will be done using Kumologica designer. The Kumologica flow will be then deployed on AWS Lambda. After the deployment we will copy the gateway endpoint which is then configured on the outboundMessage section in Salesforce.
Prerequisite
- Salesforce account — For configuring the outbound message connecting contact module.
- Kumologica Designer — Download the designer for building the flow.
- AWS account — For running the Kumologica flow as lambda and for hosting the SQS queue.
Implementation
We will be creating ContactInboundService flow in Kumologica designer. This flow will expose the endpoint on the resource path /sfdc.
ContactInboundService flow
Steps
- Open Kumologica Designer, click the Home button and choose Create New Kumologica Project.
- Enter name (for example ContactInboundService), select directory for project.
- Press Create Button.
- Drag and drop EventListener node to the canvas the provide the following configuration.
Display Name : POST /sfdc
Provider : AWS
Event Source : Amazon API gateway
Verb : POST
URL : /sfdc
- Add a Logger node and wire with the EventListener node. Provide the following message.
'Request received - ' & msg.payload
- Drag and drop the Set-Property node to the canvas and wire it with the logger node. Provide the following configuration.
Display Name : ConvertToString
Rules :
Set : msg.payload
To : J: $string(msg.payload)
Note: J : is the JSONata expression to be selected from the drop down.
- Add the SQS node to canvas and wire it with the Set-Propery node. Provide the following configuration.
Operation : SendMessage
QueueUrl : <<SQS queue url>>
MessageBody : msg.payload
Note: Ensure that you have an SQS queue created in your AWS account and you have the queue url for configuring in the SQS node. Refer : https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-getting-started.html#step-create-queue
- Add EventListener End node and wire with the SQS node. Provide the following configuration.
Display Name : Success
Status Code : 200
Content-Type : application/json
Payload : {"status": "completed"}
Deployment
- Select AWS icon on the right hand side vertical tab of Kumologica designer, select your AWS Profile.
Note: If you haven’t mapped the your local AWS profile with the designer then you may follow the below video to configure it.
- Click Connect. If successfully connected will show the rest of the configuration options.
- Set the Memory to 512mb and Timeout as 20 seconds.
- Go to “Trigger” section under cloud tab and select the Amazon API Gateway trigger.
- Post successful deployment copy the endpoint url from the Kumologica terminal. We will need this endpoint for configuring the OutboundMessage in Salesforce.
Url eg: https://ii48n22.execute-api.ap-southeast-2.amazonaws.com/test
Configuring OutboundMessage in Salesforce
- Go to your salesforce Account and search for Outbound Messages.
- On the Outbound Message screen , create a “New Outbound Message”
- Select the object as “Contact” and Click Next. Provide the following details.
- Click Save. Now you have created an Outbound Message.
- Let’s map the Outbound Message to the workflow rule.
The above rule configuration ensures that anytime a contact is created with the description that starts with “ABC” the workflow will invoke the Outbound Message.
Now we will map the “ContactWebhook” OutboundMessage we have created in the earlier step to this workflow rule we are configuring.
- From “Add Workflow Action” click on “Select Existing Action”.
From the type select “OutboundMessage”.
Now you will see the “ContactWebhook” in the Available Actions list. Add it and Save.
- Now we are ready to rock n roll.
Testing
- Go to the Salesforce contact module and create a new contact.
- Go to the AWS account and look into the SQS queue. You will observe that a SOAP message is now available in the queue.
Posted on April 5, 2021
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.