# Salesforce recipes

> Text leads and contacts when records change, and bring replies back as tasks.

Three recipes for Salesforce. Each names its trigger and the BlueBot step, lists the fields to map and says how to test it with your own number before anyone else gets a text.

## How Salesforce connects

- **[Zapier](https://usebluebot.com/docs/zapier)**: BlueBot’s Zapier app has a Send Text action and instant triggers for incoming texts and every change of state.
- **[Make](https://usebluebot.com/docs/make)**: BlueBot’s Make app sends texts and starts scenarios when a text comes in or changes state.
- **[API](https://usebluebot.com/docs/api)**: Your own code calls BlueBot’s REST API and listens to its signed webhooks.

## Text new web leads

| Part             | What it is                                          |
| ---------------- | --------------------------------------------------- |
| Trigger          | Salesforce’s New Record trigger in Zapier for Leads |
| Action           | BlueBot’s **Send Text** action                      |
| Connects through | [Zapier](https://usebluebot.com/docs/zapier)                              |

### Steps

1. Start a Zap with Salesforce’s New Record trigger on Leads.
2. Add a Filter by Zapier step so only leads from your web form go on.
3. Add BlueBot’s Send Text action, map the lead’s mobile phone to To and write the text.

### Map the fields

| BlueBot field                | Map it to                                                                                                                                       |
| ---------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- |
| To                           | The person’s mobile number from Salesforce. US numbers can leave off the +1.                                                                    |
| Text                         | Hi {{first_name}}, this is Casey from Northwind. I got your request. Is now a good time for a quick call?                                     |
| `{{first_name}}` in the text | Salesforce’s first name field.                                                                                                                  |
| Metadata                     | `source` set to `salesforce`, and `record_id` set to the record’s id, so the status and reply webhooks for this text can find the record again. |
| Service                      | Auto, the default: iMessage when the person uses it, otherwise SMS through your iPhone.                                                         |

### Test it

Put your own number in **To** and press **Test step**. A text arrives on your phone from your own number, and Zapier shows the message BlueBot returned with `state: "queued"`. Then map Salesforce’s field back into **To** and turn the Zap on.

## Make a task from each reply

| Part             | What it is                                                                       |
| ---------------- | -------------------------------------------------------------------------------- |
| Trigger          | BlueBot’s New Incoming Text trigger in Zapier                                    |
| Action           | BlueBot’s **New Incoming Text** trigger starts it, and Salesforce takes the text |
| Connects through | [Zapier](https://usebluebot.com/docs/zapier)                                                           |

### Steps

1. Start a Zap with BlueBot’s New Incoming Text trigger.
2. Find the lead or contact whose phone matches the sender’s number with Salesforce’s Zapier app.
3. Create a Task on that record with the words of the text.

### Map the fields

| From BlueBot    | Into Salesforce                                                                                                                                              |
| --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| **From**        | The phone number to find the person by in Salesforce. It’s in E.164 (`+15555550123`); search by the last 10 digits if Salesforce stores numbers another way. |
| **Text**        | The words, for a note, a row or a message. Null when the person sent only a picture.                                                                         |
| **Received At** | When it came in, in UTC.                                                                                                                                     |
| **Files**       | Pictures and voice memos. Each `url` works for an hour, so copy a file you want to keep.                                                                     |
| **Chat ID**     | Set when the text came in a group chat; null for a one-to-one text.                                                                                          |

### Test it

Text your BlueBot number from another phone, one you’ve texted through BlueBot before, then press **Test trigger** in Zapier. It loads that text with its fields, ready to map. BlueBot copies texts from people you’ve texted through it, unless you set **Which chats to copy** to **Everything**.

## Mark a lead when a text fails

| Part             | What it is                                      |
| ---------------- | ----------------------------------------------- |
| Trigger          | A text fails (BlueBot’s message.failed webhook) |
| Action           | Salesforce acts on what BlueBot reports         |
| Connects through | [API](https://usebluebot.com/docs/api)                                |

### Steps

1. Send texts from your code with POST /v1/messages and the lead’s ID in metadata.
2. Listen for message.failed, which carries the same metadata.
3. Update the lead through Salesforce’s API so your team knows the number didn’t take a text.

### Map the fields

| From BlueBot          | Into Salesforce                                                                           |
| --------------------- | ----------------------------------------------------------------------------------------- |
| `data.state`          | `sent`, `delivered`, `read`, `failed` or `expired`, for a field or a filter.              |
| `data.metadata`       | The `record_id` you sent with the text, to find the record it was for.                    |
| `data.failure.reason` | Why a failed text didn’t go: `not_on_imessage`, `messages_refused` or `file_unavailable`. |
| `data.to`             | Who the text was for.                                                                     |

### Test it

Send one text to your own number, then look for the event. To try the step without sending anything, `POST /v1/webhooks/{id}/test` sends an example of any event type to your webhook.

## Before you turn it on

- Text only people who asked to hear from you. Anyone who replies STOP goes on your stop list, and BlueBot cancels texts to them. [Stop words](https://usebluebot.com/docs/concepts/stop-words)
- A text that can’t go yet waits with a hold rather than failing: quiet hours, your Mac away, a daily limit. [Holds](https://usebluebot.com/docs/concepts/holds)
- [Salesforce with BlueBot](https://usebluebot.com/integrations/salesforce) on the integrations page says what else the two do together.
