Getting Started

Learn through 101 guides and easy solutions.

Twilio SMS Messages and Pardot: A Complete Guide

Twilio SMS Messages and Pardot: A Complete Guide

min. reading

We’ve previously talked about External Actions and External Activities, with some general ideas of how each can be applied separately. Where the real power comes in, is tying them together. In this blog post, let’s explore using a Marketing Cloud Account Engagement (Pardot) Engagement Studio Program to send an SMS message and act on the Prospect replying to it.

Installation and Configuration for Twilio SMS Messages and Pardot

Say your company is going to attend a big conference, and you want to see if there is interest for nearby Prospects (far enough in their journey with you) to meet with your team. A quick text asking if they are interested, followed up with sales outreach and/or a “book a meeting” page is a great example of sending the right message at the right time.

There’s a lot of installing and configuration needed to pull this off: 

  1. Set up Twilio for Salesforce
  2. Set up Twilio for Pardot
  3. Create a Flow to be called by External Action
  4. Configure the Marketing App Extensions
  5. Create the Engagement Studio Program
  6. Handle SMS Responses with a Flow

Set Up Twilio for Salesforce

The first thing we are going to do is to integrate Twilio with our Salesforce org. Twilio has a really good instruction video for setting things up, we highly recommend watching it and following along.

Install instructions written out can be found here:

Setup Twilio for Pardot

Once Twilio is set up for Salesforce, there are a couple of steps to enable it to work with Pardot.

  1. Add the B2BMA Integration User as a “Twilio for Salesforce” Licensed User (enables Pardot to send the SMS)
    • In Salesforce Setup, use the Quick Find window to search “Installed Packages.”
    • Click Manage Licenses beside the Twilio package, add the B2BMA Integration User
  2. Add the “Twilio User” Permission Set to B2BMA Integration User
  3. Create a “Latest SMS Campaign” field on both the Lead & Contact (Lookup to Campaign). You do not need to sync this field with Pardot, though the B2BMA Integration User should have access to edit the field values.

4. Create a Pardot custom field named “MobilePhone.” Sync this field to the Salesforce field of the same name. The Twilio Lightning Components you added when setting up Twilio for Salesforce relies on the MobilePhone field.

For the purpose of this blog post, we are not taking into consideration whether the prospect has opted in or out of SMS messages. Though, you should consider this when putting together a solution in your environment.

Create a Flow to be called by External Action

External Actions can be powered by APEX, External Services (which make APEX behind the scenes), and Flows. Whenever possible, we recommend using a Flow, as it makes it a bit easier to test and troubleshoot later on.

  1. From Salesforce Setup, use the Quick Find window to search for “Flows.”
  2. Select Create New Flow, then choose Autolaunched Flow.
  3. We need to create a few resources (variables) that will be exposed to Pardot and provide the information we need. These should all be set to:
    • Resource Type: Variable
    • API Name: varPhoneNumber (The phone number we are sending the SMS to)
    • Data Type: Text
    • Available for input: checked
  4. Repeat step 3 for the following variables:
    • varCampaignId – The Salesforce Campaign ID we want to use for tracking
    • varCrmLeadContactId – The Salesforce ID of the Lead or Contact record
    • varMessage – The text we want to include in the SMS message
    • varCampaignStatus – the CampaignMember status you want to use when sending the SMS. This is optional, you could just hard-code the flow to use “Sent”
  5. Create a couple more variables to help simplify the flow. These will be Text, and we will not be selecting the “Available for input” checkbox (they are only used within the flow)
    • varLeadId – set only if the varCrmLeadContactId is a Lead (Decision-based on prefix starting with 00Q)
    • varContactId – set only if the varCrmLeadContactId is a Contact (Decision, prefix starting with 003)
  6. The Flow itself will be composed of a few sections
    • Send SMS via Twilio
    • Update the “Latest SMS Campaign” field on Contact/Lead records with the Campaign ID if the Prospect is synced to CRM
    • Create/Update CampaignMember record for the Contact/Lead and Campaign
    • When done, your Flow might look something like this:
  7. Save and Activate your Flow

Configure the Marketing App Extensions

Next, we need to actually expose the Flow to Pardot. This is done with Marketing App Extensions in Salesforce Setup.

  1. In Salesforce Setup, use the Quick Find window to search for “Marketing App Extensions”
  2. Create a new extension named “Twilio” (don’t create a bunch of tests, currently these cannot be removed and you have a limit of 10)
  3. In the Related Tab, for Action Types click New.
    • Type Action Name: Send SMS w Campaign, type in a good API name
    • For Invocable Action, search for your newly created Flow
    • Once selected, the Action Schema will automatically fill in. We will want to edit it
      • adjust titles, set merge for varCrmLeadContactId, varPhoneNumber. This enables the system to automatically grab the values from the Prospect record.
      • remove view components for varCrmLeadContactId and phoneNumber. Since they are being auto-populated, no need to ask for the values.
      • Set varMessage, varCampaignId as required
    • Make sure “Active in Automations” is checked.
    • Once done, it will look like this (we adjusted the line spacing to make a decent screenshot:
    • Note: because you are directly editing JSON, if mistakes are made there isn’t great feedback in terms of errors upon saving. We’ve found it best to just click Cancel and try again, being a bit more careful.
  4. Next, we will create an Activity Type. This will enable us to send information back to Pardot when a Contact/Lead replies to one of our messages (we will walk you through handling this later in the post).
    • For Activity Name & API Name, simply use “FirstReply”
    • Make sure “Active in Automations” is checked.
  5. Lastly, we will enable these Actions and Activities for our Business Unit(s). Assign this Extension to your Business Unit(s) by clicking New, and choosing the Business Unit.

Create the Engagement Studio Program

Next, we will build an Engagement Studio Program that will begin to tie this all together.

  1. In Pardot, navigate to Automations > Engagement Studio
  2. Select + Add Engagement Program
  3. Add a new Action, choose “Send SMS w Campaign” (bottom of the list)
    • SF Campaign ID: provide an 18-character Campaign Id
    • Campaign Status: provide a valid CampaignMemberStatus for the Campaign
    • Message: let your creativity shine!
    • When done, it should look something like this:
  4. Next, we want to Listen for their First Reply to our Campaign. Add a new Trigger
    • Choose External Activity 
    • Extension Name: Twilio
    • Activity Type: FirstReply
    • Value: The Campaign Id you provided in the earlier step. We want these to match
    • Specify when the Trigger should be evaluated.
    • When done, it should look something like this:
  5. Next, you can decide what happens if the Prospect does reply. In our example, we add the Prospect to a Suppression List (as ideally, they are now engaging with Sales, we don’t want to keep bugging them right?

Ok, our Engagement Studio Program is done. How will it know when someone has replied to our message?

Handling SMS Responses

With the Twilio integration, we can create a Record Triggered Flow based on the “Twilio Message” object, looking for inbound SMS messages. When a message is received, we can check to see if we should take action (based on the “Latest SMS Campaign” field still having a value).

In our example, we will use the Pardot API to send an External Activity record (with some help from a free AppExchange package) to allow our Engagement Studio Program’s trigger to work, update the Campaign Member Status for the Lead/Contact and create a Task for Sales to follow up.

To begin, we will install & configure the Flow Actions for Pardot package, which makes it easy to make Pardot API calls (since you can’t natively do this within Salesforce).

Create the Flow

Next, we will create our Flow:

  1. From Salesforce Setup, use the Quick Find window to search for “Flows”, and create a new Flow
  2. Choose a Record Triggered Flow
    • Select “Twilio Message” as the Object
    • Trigger when a Record is created
    • Entry Conditions: TwilioSF__Direction__c Equals “inbound”
    • Optimize for Actions and Related Records, and Include a Run Asynchronously path.
  3. We will need a decision based on the Twilio Message being linked to a Lead or Contact. The logic we use for both Leads and Contacts will be similar, let’s start with Leads
  4. Use a Get Records element to retrieve the Lead based on the ID matching the Twilio Message’s Lead value
  5. Check to see if we need to take action on the Lead by checking if the “Last SMS Campaign” field has a value. If it does not, we can end the flow.
  6. If “Last SMS Campaign” does have a value, create a new Element: “Pardot – External Activity Add to Prospect”
    • Activity Type: FirstReply (this is what you provided when setting up the Extension earlier in the post)
    • Extension Name: Twilio (again, this was setup earlier)
    • Prospect Email: Grab the Email value from the Get Records element in Step 4 above
    • Value: Grab the “Latest SMS Campaign” value from the Get Records element
    • When done, it should look something like this:
  7. Update Lead’s CampaignMember record, create a new Update Records element
    • Specify conditions to identify records, and set fields individually
    • Update records of object: Campaign Member
    • Update records matching the CampaignId and Lead Id from the Get Records element in Step 4 above.
    • Set the Status to what you need it to be (we chose Responded). You will really want consistency across your Campaigns to reduce complexity.
    • When done, it should look something like this:
  8. Create a Task for Sales. You can do this with either a Quick Action, or with a Create Record element, it really depends on your setup and what level of detail you want to provide.
  9. After taking all of our actions, we will want to clear the “Latest SMS Campaign” field on the Lead, so that we don’t take the same actions the next time the person replies.
  10. Repeat steps 4-9 for a Contact, being sure to select the Contact’s Get Record variable in steps 5-9
  11. When done, your Flow should look something like this:

Phew, it’s all done. Give it all a try by sending your own Prospect record through the Engagement Studio Program. It will take a while once started, but you should get your Text message. Once received, check your Lead/Contact record to make sure it was stamped correctly and that you were added to the right Campaign.  

Send a reply from your phone and check your Lead/Contact record again to make sure that your Campaign Status changed, and check Pardot to see that your External Activity record was created.


As with any “internet example,” there are a few things that we skirted around to avoid extra complexities, and there are a few things that might not be obvious.

  • This solution is best run when all Prospects (entering the ESP) are synced in Salesforce.
  • Prospects that are not synced to Salesforce, if they reply Twilio will create a Lead record and it might not be synced to Pardot fast enough to receive the External Activity resulting in a break in the process.
  • Our example handled ANY SMS response in the same way. While it is possible to add keywords and build branching logic into Flows and Engagement Studio Program, the solution will get exponentially more difficult to maintain.
  • In our example, we created the Task in the Flow instead of the Engagement Studio Program. We made this choice as it can give us more flexibility in what is provided in the Task and how it can be assigned. If you really want to keep that in the Engagement Studio Program, you certainly can!
  • Twilio does charge PER SMS, so be careful when selecting your audiences, especially during testing!
  • Working with External Activities in Pardot is still somewhat limiting, in that you can only look for “a record with a specific value.” You can’t look for External Activities created in the last X days or anything like that, so it really is a “First Response” mentality.
  • If you have multiple Twilio sending numbers, you could expose this as an input variable in your Flow and External Action, so that it can be specified when sending a message.

Happy Building! And Let Us Know If You Need Help

External Actions and External Activities are a great way to leverage other solutions with Pardot. But as you saw, there is still a lot that needs to be built to glue it all together. 

We hope this guide is helpful so you can take it on and build this solution yourself. And you can always reach out to Sercante to build this solution for you if you’re ready to hand it over to the experts. Visit our contact page here to raise your hand, and we’ll get back to you ASAP.

Subscribe to The Spot

This field is for validation purposes and should be left unchanged.

Salesforce Training Courses


Top 5 Recent Posts

  • Adam Erstelle is a Developer with Sercante. He loves learning about and solving really interesting challenges with Pardot and Salesforce often by building some cool tools.

Leave Your Comment

Related Articles

Bot Single Post