DEV Community

Cover image for Serverless integration with Salesforce using Kumologica
ab73863 for Kumologica

Posted on

Serverless integration with Salesforce using Kumologica

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

  1. Open Kumologica Designer, click the Home button and choose Create New Kumologica Project.
  2. Enter name (for example ContactInboundService), select directory for project.
  3. Press Create Button.
  4. 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

Enter fullscreen mode Exit fullscreen mode
  1. Add a Logger node and wire with the EventListener node. Provide the following message.

'Request received - ' & msg.payload

Enter fullscreen mode Exit fullscreen mode
  1. 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) 

Enter fullscreen mode Exit fullscreen mode

Note: J : is the JSONata expression to be selected from the drop down.

  1. 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

Enter fullscreen mode Exit fullscreen mode

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

  1. 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"}

Enter fullscreen mode Exit fullscreen mode

Deployment

  1. 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.

Set profile video

  1. Click Connect. If successfully connected will show the rest of the configuration options.
  2. Set the Memory to 512mb and Timeout as 20 seconds.
  3. Go to “Trigger” section under cloud tab and select the Amazon API Gateway trigger.

  1. 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

Enter fullscreen mode Exit fullscreen mode

Configuring OutboundMessage in Salesforce

  1. Go to your salesforce Account and search for Outbound Messages.
  2. On the Outbound Message screen , create a “New Outbound Message”
  3. Select the object as “Contact” and Click Next. Provide the following details.

  1. Click Save. Now you have created an Outbound Message.
  2. 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.

  1. 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.

  1. Now we are ready to rock n roll.

Testing

  1. Go to the Salesforce contact module and create a new contact.
  2. Go to the AWS account and look into the SQS queue. You will observe that a SOAP message is now available in the queue.

Top comments (0)