Send COVID-19 Vaccine Appointment Reminders with Salesforce Flow and Twilio

December 16, 2020
Written by

1.png

With countries around the world beginning to approve COVID-19 vaccines for public use, we've seen a lot of interest in implementing vaccine notifications and appointment reminders. This tutorial will show you how to set up Twilio SMS notifications with Salesforce’s Automation Flow Builder so that you can remind people to sign up to get both parts 1 and 2 of the vaccine.

Let’s look at a user journey that we might want to support as a local public health authority. We’ll have patients sign up via a web-to-lead form to be put into our contact database. We might also receive data from health providers.

 

Vaccine solution diagram

For this tutorial, we’re going to focus on the second half of the workflow above: sending SMS reminders. If you’re interested in sending one-off SMS broadcasts, check out our documentation on using the Twilio for Salesforce Campaign Component.

Once we’re ready to begin vaccine distribution, we’ll want to start sending out SMS reminders to book an appointment. When the patient has booked their first appointment, we’ll send them an SMS reminder 24 hours before the appointment to help make sure they arrive on time.

After the patient’s first appointment we’re going to want to prompt them to come in between 3-4 weeks later to get their second dose. We’ll ping them daily until they’ve booked and attended their second appointment. By the time we’re done, you’ll have a vaccine reminder flow that looks like this:

Overview diagram showing entire workflow

If you’d like to jump straight to the flow definition XML file, you can find that here. Note: this is a hypothetical workflow. The specific needs for your locality and organization will vary, and we recommend referring to local health officials for guidance, or contacting us to discuss your needs.

Prerequisites

Let’s start out with the prerequisites. The best way to get started is to follow the steps in this 10-minute Twilio for Salesforce setup video. Here are the steps at high level:

  1. Create a Twilio account
  2. Install Twilio for Salesforce from the Salesforce AppExchange
  3. Add your Twilio API credentials to Twilio for Salesforce
  4. Purchase a phone number in your Twilio account

Create Appointment DateTime Fields

Begin by adding two Date/Time fields to the Contact object in the Object Manager. We’ll call them First Appointment Date and Second Appointment Date:

Screenshot of the Salesforce object manager with custom fields.

We’re also going to add a checkbox field called “Vaccine Flow Complete” so that we can keep track of who completed the flow.

Screenshot showing new custom field being created.

Flow set up

Now that our contact has the right fields, let’s create a new flow. Select “Schedule Triggered Flow” as the flow type:

Screenshot of selecting the scheduled-trigger flow option in Salesforce.

Then set the flow to run once per day at 9:00am:

Screenshot showing how to set the start date and time plus cadence of the triggered workflow.

Under the schedule section, add a trigger condition so that our flow only runs for contact objects where “Vaccine Flow Complete” is unchecked. This keep contacts that have already completed the vaccination process out of our reminder flow:

Choosing the Object and Setting Filter Conditions

 

Reminders to Book the First Appointment

Now for SMS! The first message will tell the patient to schedule an appointment if they don't already have one.

We’re going to add a decision element that determines if the first appointment date is blank. If it is, we’ll send the SMS using an Apex action.

Decision to send a reminder or not

Decision configuration modal

Drag an Apex Action on to the page and search for Twilio, then click on the “Twilio Send SMS Message” action:

searching for the Twilio Send SMS Apex action

You’ll be able to fill in the number you want to send to, as well as the message body. For the “To Mobile Number” pick the contact’s MobilePhone.

For the content of the message, just add some placeholder text for now, e.g. “Reminder to create your first appointment.” We’ll come back and make this dynamic text using a text template later on.

Editing the Twilio Send SMS Message

Note: for the sake of the tutorial, we’re going to assume that the user will click a link that allows them to book an appointment and updates the First Appointment Date field.

Sending a Reminder 24 Hours Before the First Appointment

Next, we want to send a reminder 24 hours before the appointment. Before creating the decision, let’s create a Formula that gives us the date for the day before the first appointment.

Click on “Manager” new resource, and then select Formula.

  1. Name the formula “Day before first appointment”.
  2. Use the “Insert a resource…” box to get the contact record’s first appointment date field
  3. Wrap the “First Appointment Date” in a DATEVALUE formula to only get the date (and not the time) of the appointment.
  4. Then add -1 to the end of your formula subtract one day and get the day before the appointment.

When you’re done, the formula should look something like this:

Editing the formula for finding the date one day before the next appointment.

Add a new decision to the page and connect it to the previous decision’s default outcome:

Overview of the flow built so far

Within the decision, create a new condition called “Send first 24 hour reminder” and then check if our DayBeforeFirstAppointment formula matches the current day that the flow is running.

Creating the decision to send the first 24 hour reminder

Now we can create another apex action that sends out our 24 hour reminder text. For the message, just add a placeholder, e.g. “Appointment 1 24 hour reminder.” Again, we’ll come back and customize this with text templates.

Booking the Second Appointment

We’re making progress. Our contact has attended their first appointment, but for COVID-19 vaccines it’s likely they’ll need a second appointment to receive part two of the vaccine 3-4 weeks later.

For our next trigger we’ll set up another formula resource that calculates the date seven days after the first appointment (our contact will get a bit of a break from all the reminders).

This formula is similar to the “Day Before First Appointment” formula we just created:

Creating the formula to calculate 7 days after the first appointment

Since we want the date seven days after the first appointment, we’ll add “+ 7” in the formula.

Next, add another decision step and connect it to the previous decisions default outcome so that your flow looks like this:

Overview of the flow built so far

Here are the conditions we want within our third decision:

  • If the date that the flow is running is more than 7 days after the first appointment date.
  • AND there’s no second appointment date on our contact yet, we’re going to send them a text.

The decision to send one week after the first appointment or not

Once again, we’re going to add an apex action that sends an SMS. Set “Reminder to book your second vaccine appointment” as a placeholder for now:

Sending a reminder to book the second appointment

Sending a Reminder 24 Hours Before the Second Appointment

Our last step in the user journey is to send a reminder 24 hours before the second appointment. Create a formula using the Second Appointment Date field and subtracting 1 to determine the day before the appointment:

Calculating the date one day before the second appointment

Just like in our second decision, we are going to check if the day before the appointment is equal to the day we’re running the flow:

Sending a reminder 24 hours before the second appointment

Then, create an apex action and – you guessed it – select Twilio Send SMS and enter the record’s mobile phone number and a placeholder that says “2nd appointment 24 hour reminder”:

Sending the appointment reminder 24 hours before the second appointment

Mark the Contact’s Vaccine Flow Complete

As the last step in our flow, we’re going to update the Vaccine Flow Complete field on the contact to be “true” so that the flow no longer runs for our contact. This is helpful for tracking, and means that our flow isn’t looping through records that don’t need SMS reminders.

Drag the Update Records element onto the flow and connect it to the last Apex action. Inside the modal, take the following steps:

  • Select “specify conditions to identify records.”
  • Then select contact as the record type and match the contact ID to the flow record ID.
  • Under the set field values section, set the “Vaccine Flow Complete” field to be true.

Updating the contact record to be marked complete.

Testing with Flow Debug

We’re at a good place to test our flow, so go ahead and click the “debug” button to run it for a record in your instance.

 

The debug button
Sample log output from running the debug.

This won’t actually send SMS messages yet, but it will tell you which action was run. Try out some of these scenarios:

  • If both appointment date fields are blank, it should result in the first SMS.
  • If the first appointment date is tomorrow, it should result in the second SMS.
  • If the first appointment date was more than seven days ago and the second appointment date is blank, we should get the third SMS.
  • And lastly, if the second appointment date is tomorrow, run the 4th SMS and update the contact.

Customizing Messages with Dynamic Templates

So far we’ve been adding placeholder text to each of our SMS, but it would be great to be able to send personalized SMS to each contact that includes their name.

We can do this with text templates. Create a text template by clicking on Manager, new resource, then selecting text template. Be sure to select “View as Plain Text” otherwise HTML tags will be included in your SMS:

Creating a text template

As you can see, we’re using {!$Record.FirstName} to template in a field from the contact record.

Now we can save the text template and add it to our first SMS action. Replace the placeholder text with the template, like this:

Setting an input value

Tip: it’s a good idea to keep SMS to less than 160 characters in length. Most carriers automatically concatenate longer messages, but some might deliver them separately. Read more about message character limits here.

Send a Test Message

As a final test, let’s send an actual reminder text:

  • Consider deleting all other contacts in your Developer Org, or adding another criteria so that the flow only runs for your contact (e.g. by filtering on FirstName).
  • Make sure your contact’s MobilePhone field is set.
  • Temporarily edit the flow to start in one minute. So for example, if it’s currently 3:19pm for you, set it to run at 3:20pm.
  • Click save and activate in the top toolbar. If everything went well you should see an SMS just a few minutes later.

Example text message

Wrap Up

Great work getting this far. We’ve covered the basics of sending SMS on a schedule with certain conditions in Salesforce’s Flow platform.

Next steps:

That’s it for now. Thanks for reading and we can’t wait to see what you build.