Salesforce and Slack Integration Using Mule 4

RajaMani R
Another Integration Blog
6 min readJul 24, 2023

In this article, we will be displaying the Salesforce and Slack integration using Mule 4.

The main purpose of this integration is to automatically get the new records from Salesforce Account object details based on the ‘first name’ given and sending only the message first name from object details to the slack channel.

Overview

  1. Introduction to MULE 4
  2. Demonstrating a Practical use case using SALESFORCE and SLACK

Introduction to Mule 4:

Mule is a lightweight enterprise service bus (ESB) and integration framework provided by Salesforce. The platform is Java-based and can interact between other platforms such as .NET using web services or sockets.

The architecture is a scalable, distributable object broker that can handle interactions across legacy systems, in-house applications, and almost all modern transports and protocols.

Let’s start with creation of custom fields in Salesforce

  1. Login to Salesforce Org(Lightning Web Experience) and we create Custom fields in the object field where I opted Account as my object in salesforce workbench.

2. Once the creation of object field Account, we will be searching in the App launcher regarding accounts and start creating custom fields.

3. We have created custom fields as below:

firstname__c, lastname__c, PAN number__c, Phone_Number__c

Practical Use case:

In the following part of the blog we will explore how to integrate between a Salesforce and slack.

Salesforce: Salesforce is a cloud-based software company that provides businesses with tools that help them find more prospects, close more deals, and provide a higher level of service to their customers.

Slack: Slack is a messaging app which is almost ubiquitous in workplaces

GOAL💡:

  • Sending new inserted data in salesforce and when ever the new object insert, the flow gets triggered.
  • Later we setup a query in workbench and add in the anypoint studio.
  • We will create our own channel and we will be mapping the name in the implementation.
  • Based on the channel mapping, the message will be sent.

Let’s INTEGRATE🏃‍♀️:

  1. Login to Anypoint Studio and create new project.

2. Add the Salesforce module from Exchange if its not available in studio, drag and drop the salesforce On New Object into canvas.

3. Give the configurations of salesforce login username, password and security token. For resetting security token navigate to salesforce account →view profile →settings →my personal information →reset my security token.

4. Once done with configurations, click on test connection and make sure the connection is successful.

5. Give the Object type as Account.

6. Add a logger and give the message as start flow.

7. Select a salesforce Query connector, configure it and write a SOQL query in workbench with required fields and copy the same query to anypoint studio.

SELECT firstname__c,Id,lastname__c,PAN_Number__c,Phone_Number__c FROM Account ORDER BY CreatedDate DESC LIMIT 1

Above is my query for the reference where I have set desc limit to 1 means it returns atmost only one value where firstname__c value will be retrieved from Order By in descending order.

8. Add a transform message and set a message where new record has been inserted and have concatenated the payload[0].firstname__c where my firstname value will be the message sent to my slack channel as String.

9. Add one more transform message where I have set the json payload as given below. My slack channel name is “develop” and added the value “payload.message” to the key “text”.

10. Before we can send a message to Slack from MuleSoft, we need to create a Slack App. Navigate to https://api.slack.com and click on Create App

11. In the next screen, click on From an app manifest

12. Select the workspace you want to publish the app to and click on Next. In the next step, write the YAML code over the default app manifest: It should look like the screenshot below before you click on Next

13. In the last step, click on Create

14. Before we can use the Slack App, we need to install it into a Workspace. Click on Install to Workspace.

14. Select a channel to allow the app to post to by default and click on Allow.

15. You’ll return back to the Basic Information section of your newly created app. In the App Credentials section, need to copy Client ID and Client Secret. We’ll need these to configure the Slack Connector in Studio later.

16. Select a Slack Send Message component from mule palette and configure consumer key, consumer secret, authorization url, access token url and scopes.

17. Then scroll down, need to configure the Http listener and perform TLS configuration. Directly I have attached the screenshot below.

18. Next, scroll down we find the oauthCallbackConfig section. Fill in the Callback path: and Authorize path: fields to match the following screenshot below.

19. Then click on OK to close the screen. Adding another transform message and just passing the payload and add end logger.

20. Once done with configurations, deploy the project on local server. Then we need to authorize Oauth in the browser.

[a] Copy the below url and check in the local browser https://localhost:8084/authorize

[b] Allow the permission to access to the slack workspace

21. Go to the Salesforce Org and insert New record from Account object

22. Now we can see the message is inserted in the slack channel with the message field firstname__c

Conclusion:

  • Implemented Salesforce-Slack Integration. We created a new app in slack.com and we got credentials and same thing we will be configuring in the Slack connector in Anypoint Studio.
  • Any new record inserted into Salesforce Org, these records will be reflected in the Slack channel.

Please provide feedback. It will help to improve the content.

Thank you for reading this article! If you found this response useful, please consider giving it a ‘clap’ and Follow me for more helpful articles and insights in the future.

--

--