Send SMS Messages from Process Builder
Process Builder is a popular tool for building automated workflows in Salesforce. Twilio for Salesforce exposes two global Apex classes: Twilio Send SMS
and Twilio Send to Studio
that you can use to send out automated SMS messages when certain conditions are met. Common uses of Process Builder include:
- SMS notifications.
- Appointment reminders.
- Customer satisfaction surveys.
Process Builder actions
Twilio Send SMS Message
allows you to send a text message from Process Builder. This Apex class is useful for single-message use-cases such as alerts and notifications.
Twilio Send to Studio
allows you to initiate SMS and Voice chatbots using Twilio Studio, Twilio’s drag-and-drop visual editor. This Apex class is useful for initiating longer conversations that might require if...then
branching.
How many licenses do I need if I’m using Process Builder?
The answer to this question depends on which users are running your automation flow. See “How many seats do I need?” in the FAQ for more details.
Send SMS messages with Process Builder and Twilio for Salesforce
Ready to get started sending simple SMS alerts? Follow the instructions in the video below.
Twilio Send SMS Message
parameters:
Parameter | Description |
Message |
The body of the SMS message that you would like to send. This can be static, a field reference, or a formula (useful for templated messages). Note the message length determines the number of segments. |
To Mobile Number |
The phone number you want to send the message to. This can be static, a field reference, or a formula. |
From Mobile Number |
The phone number you want to send the message from. This can be static, a field reference, or a formula. |
Send to Studio with Twilio for Salesforce
Interested in crafting interactive bot conversations with your users? Learn how you can launch SMS bots using Twilio Studio and the Salesforce Process Builder in this video:
To configure the Twilio Send to Studio
Apex class, provide the following values:
Parameter | Description |
From Number |
The phone number you want the Studio flow to be sent from. Currently we only support sending from a specific number, not a messaging service. This might mean your chat bot will contact a user from a new number. |
Studio URL |
The Rest API URL that will call your Studio flow. Example: https://studio.twilio.com/v1/Flows/FWXXXXXXXXXXXXXXXXXXXXXXXXX/Executions . To find your Studio flow API URL, click on the gear icon in the top-right corner of the flow’s trigger. |
To Mobile Number |
The number that the chat bot will send messages or make calls to. |
Parameters |
(Optional) You can also include additional Salesforce data as context parameters in key/value pairs. This is useful if you want your chat bot to address the recipient by first name, or reference other information from Salesforce within your Studio flow under {{flow.data.your_param_key}} . |
Updating a Salesforce record with a Twilio Function
The following code sample shows how to create a Salesforce contact using a Twilio Function. Functions can be run in Twilio Studio using the Function widget. Parameters passed to the Function widget will be accessible via the event
object.
Note Before running this function, you will need to add nforce
as a package dependency in your functions configuration page:
exports.handler = function(context, event, callback) { console.log('Running function') let nforce = require('nforce'); let response = new Twilio.Response(); let oauth; // Create the connection with the Salesforce connected app let org = nforce.createConnection({ clientId: context.SF_CONSUMER_KEY, clientSecret: context.SF_CONSUMER_SECRET, redirectUri: 'https://twilio.com', mode: 'single' }); // Authenticate and return OAuth token org.authenticate({ username: context.SF_USERNAME, password: context.SF_PASSWORD + context.SF_TOKEN }, function(err, resp){ if (!err) { console.log('Successfully authenticated:', resp); oauth = resp; } let lastname = `${event.first_name} ${event.last_name}`; // Set contact data let ct = nforce.createSObject('Contact'); ct.set('lastname', lastname); ct.set('State__c', 'California'); ct.set('Phone', event.phone); ct.set('MobilePhone', event.phone); // Create contact in our SFDC org org.insert({ sobject: ct, oauth: oauth }, function(err, resp){ if(!err) { console.log('Successfully created contact'); callback(null, null); } else { console.log("Error creating contact:", err); } }); }); };
For more examples, see the documentation for nforce
, the NodeJS client library for Salesforce.
Need some help?
We all do sometimes; code is hard. Get help now from our support team, or lean on the wisdom of the crowd browsing the Twilio tag on Stack Overflow.