Salesforce Flow Integration to Send SMS via Twilio API

Hello everyone, I’m Atlas Can, and today we are going to discuss and show how to automate an integration between Salesforce and Twilio. We will walk you through the process of sending an SMS notification from Salesforce using Twilio when a new lead is created. We will assume that you already have a Twilio and Salesforce account.

We are going to use the REST API, which fosters uniformity, modularity, and scalability, making it easier to manage and expand Salesforce applications.

Twilio is a leading cloud communications platform-as-a-service (CPaaS) company that enables developers and businesses to integrate and streamline communication solutions into their applications. By offering a suite of APIs, Twilio empowers organizations to leverage voice, SMS, video, chat, and email capabilities within their software, ultimately enhancing customer interactions and user experiences.

One of the key benefits of Twilio is its scalability. The platform allows businesses of all sizes, from startups to large enterprises, to scale their communication infrastructure as they grow effortlessly. Twilio’s flexible and customizable APIs make it easy for developers to add, modify, or extend communication features without the need for extensive hardware or infrastructure investment. This adaptability enables organizations to respond quickly to changing business requirements.

Twilio does offer a paid addon for Salesforce integration, but it’s in the beta stage and does not cover SLA support. You can do much more with Declarative Webhooks and build other integrations!

Business Use Case for Integrating Salesforce and Twilio

With the integration of Salesforce and Twilio, you’ll be able to streamline your communication process and enhance your customer experience. By automating the SMS notifications when a new lead is created, your sales team can focus on selling without worrying about manual communication handling. This not only saves time but also reduces the risk of human error.

Furthermore, this integration brings the benefits of Twilio’s robust communication platform to your Salesforce CRM. You’ll have access to a secure, reliable, and flexible messaging platform that supports a variety of channels and communication methods. Combining the power of Salesforce and Twilio will help you grow your business by making it easier to engage with customers and prospects.

Additionally, having communication data directly in Salesforce allows for better reporting and analysis. You can easily create reports and dashboards to track communication metrics and gain insights into your sales performance. This will help you make data-driven decisions to optimize your sales strategy and improve your revenue.

Twilio REST API Configuration

In this simple integration scenario, we’ll create a connection between Salesforce and Twilio using REST APIs to send an SMS notification when a new lead is created in Salesforce.

First, you need to get your Twilio Account SID and Auth Token. Log in to your Twilio Console and find these credentials on the Dashboard. Make sure to keep these credentials secure, as they will be used for authentication in the integration.

Also, make sure you have a verified phone number registered, this will be the phone number we will sent a text message to for our demo.

About which phone number the text will be sent from, make sure you have an active phone number, Twilio allows you to create a single phone number to which the texts will be sent and an amount of demo credit.

Create a Twilio API Callout Template in Salesforce

Let’s create our template in Declarative Webhooks:

  1. Make sure you add the API endpoint (https://api.twilio.com) registered to remote sites in Salesforce.
  2. If you look at the Postman collection by Twilio, you can see the endpoint that needs to be used, which also requires Account SID. The endpoint should be similar to this: https://api.twilio.com/2010-04-01/Accounts/AccountSIDhere/Messages.json
  3. For authorization type, we are going to pick basic and use Account SID as username and authorization token from the Twilio console as password.
  4. We are also going to make the callout request body format as Form Encoded – (application/x-www-form-urlencoded)

The first page should look like this:

On the second page include the content type in the headers as shown below.

On the next page, we will map the Lead record’s mobile phone field to our template.

Now that our template is created, let’s create a record-triggered flow so that we can make the callout using Declarative Webhooks!

Create Record-Triggered Flow in Salesforce to Send Twilio SMS

We are going to use a record-triggered flow and filter the records with the mobile phone number field populated.

Next, we are going to add an Apex Action that will fire the template with the record that initiated it. We’re populating the Record.Id so that we can access the fields of the object during the callout.

After you make sure everything is correct, go ahead and create a lead with a mobile phone number.You can check the response in the call logs section:

As you can see, it’s very easy to set up your own integration with a few steps using clicks with Declarative Webhooks.

Conclusion

I hope this example of how to send an SMS message through the Twilio API from a Salesforce Flow will be useful, and as always, thank you for reading and I will see you in the next post!

Thank you for following this quick guide.

If you want to learn more about Declarative Webhooks, please follow the links below: