# Send templates from Salesforce

Install the Zernio package to send approved WhatsApp templates from a Flow action or the Send WhatsApp button on Contacts and Leads.

## Before you start

- A WhatsApp number connected to Zernio, and a template Meta has approved ([WhatsApp templates](/platforms/whatsapp/templates)).
- A Zernio [API key](/api-keys/create-api-key) from the workspace that owns that number.
- The [Zernio package](/platforms/salesforce/connect#install-the-zernio-package) installed, with **Zernio User** assigned to the people who send.

## Add your API key

1. As a user with **Zernio Admin** and **Zernio User**, open the **Zernio Setup** tab from the App Launcher.
2. Paste the API key and click **Save key**. It is stored encrypted in the **Zernio** external credential, and one key serves the whole org.
3. The panel shows **Connected** and how many WhatsApp senders the key can use.

## Send from a Flow

In Flow Builder, add an **Action** element and pick **Zernio: Send WhatsApp template**:

| Input | What to pass |
|-------|--------------|
| Zernio WhatsApp account ID | The number to send from, its account id in Zernio |
| Template name | The exact name of an approved template on that number |
| Template language | Its language code, for example `en_US` |
| Variables | Values for the template's variables in order: text header, body, then URL buttons |
| Recipient phone | Optional: the number to send to, with its country code |
| Record ID | Used when Recipient phone is empty: its `MobilePhone`, then `PersonMobilePhone`, then `Phone` |
| Send in background | Queue the send instead of calling Zernio in this transaction |

The action returns **Status** (`sent`, `queued` or `failed`), **Message ID**, **Conversation ID**, **Error code** and **Error**. It sends through `POST /v1/inbox/conversations` with the key from the setup tab.

The account ID is on the Zernio **Accounts** page, or from `GET /v1/accounts?platform=whatsapp`.

In a record-triggered flow, put the action on the **Run Asynchronously** path or turn on **Send in background**.

## Send from a record

In **Setup > Object Manager**, open Contact (then Lead) **> Page Layouts** and drag **Send WhatsApp** into **Salesforce Mobile and Lightning Experience Actions**. On pages with Dynamic Actions, add it in Lightning App Builder.

The user picks the number and an approved template, sees its text, fills in one field per variable and sends.

## How it behaves

- Up to 20 sends per transaction go out at once and return `sent` or `failed`. The rest, and sends from a flow that already wrote records, return `queued` and go out in background jobs of 50, so a flow over 2,000 records sends all 2,000.
- A queued send's outcome shows in the Zernio inbox and webhooks, and on the record when the org is connected.
- The message shows in the Zernio inbox. With the org [connected](/platforms/salesforce/connect), it is also logged on the record with its [delivery status](/platforms/salesforce/delivery-status).
- Each message counts toward your Zernio messaging usage, and Meta bills the template to your WhatsApp Business Account.

## If it fails

| Error code | Cause | Fix |
|------------|-------|-----|
| `NO_PHONE` | No Recipient phone, and the record has no `MobilePhone` or `Phone` in international format | Fill the record's phone, or pass Recipient phone. |
| `INVALID_INPUT` | The account ID, template name or language is missing | Fill all three inputs. |
| `INVALID_TEMPLATE_PARAMS` | The variables do not fit the template | Pass one value per variable, in order. |
| `CALLOUT_ERROR` | Salesforce could not reach Zernio | Check the key on the **Zernio Setup** tab with **Test connection**. |
| "Zernio rejected this API key" on the setup tab | The key is wrong or revoked | Create a new key in Zernio and save it again. |

## Related

- [WhatsApp templates](/platforms/whatsapp/templates)
- [Send a template](/platforms/whatsapp/inbox#send-a-template)
- [Inbox sync](/platforms/salesforce/sync)