> ## Documentation Index
> Fetch the complete documentation index at: https://docs.truagents.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Salesforce with Make

> Use a Make scenario to turn TruAgents hot-lead webhooks into new or updated Salesforce Leads without code.

## Summary

A Make scenario catches the TruAgents webhook, checks whether the person is already a Lead, and then updates that Lead or creates a new one. Nobody writes code, and the Salesforce login stays in Make.

This guide is step 2 of [Send hot leads to Salesforce](/automations/hot-leads-to-salesforce). Build the TruAgents workflow first.

## Who this is for

An ops person with a Make account and a Salesforce user who can create and edit Leads.

## Before you start

* A Make plan that includes the Salesforce app. Check Make's current plans.
* A Salesforce connection in Make, using an integration user that can create and edit Leads.
* `TruAgents` added to the Salesforce **Lead Source** picklist, or pick an existing value in step 5.

<Note>
  Make labels change from time to time. If a label doesn't match exactly, look for the closest equivalent.
</Note>

## Build the scenario

The finished scenario looks like this:

```text theme={null}
Custom webhook → Salesforce: Make an API Call (look up the Lead by email) → Router
                                                                             ├─ no Lead found → Create a Record → Webhook response 200
                                                                             └─ Lead found    → Update a Record → Webhook response 200
```

<Steps>
  <Step title="Catch the webhook">
    Create a scenario. Add **Webhooks** → **Custom webhook**, click **Add**, name it "TruAgents hot leads", and save. Copy the webhook address. It looks like `https://hook.<region>.make.com/<random>`.
  </Step>

  <Step title="Teach Make the data structure">
    In TruAgents, open the workflow, click the **Send webhook** step, paste the Make address into **Endpoint URL**, and click **Save workflow**.

    In Make, click **Run once**. Then send one event: set the workflow to **Active** and email your TruAgents inbox a hot-lead message from a test address. You can also `POST` the step's **Example payload** to the Make address with `curl`. The **Test Workflow** tab never sends anything, so it can't feed Make.

    Make shows "Successfully determined" on the webhook module, and the `data` fields become available to map.
  </Step>

  <Step title="Look up the Lead by email">
    Add **Salesforce** → **Make an API Call**.

    * **URL**: the SOQL query endpoint, for example `/v62.0/query`. Check the module's help text for the base URL it adds.
    * **Method**: `GET`.
    * **Query String**: key `q`, value `SELECT Id FROM Lead WHERE Email = '{{replace(data.contact.email; "/['\\]/g"; "\$&")}}' AND IsConverted = false LIMIT 1`. Map `data.contact.email` from the webhook. The `replace` puts a backslash in front of any `'` or `\` in the address, so the address stays inside the quotes and cannot change the query.

    This module always returns one result, with `Body` → `totalSize` set to `0` or `1`. The usual **Search Records** module returns *no* results when nothing matches, which stops the scenario before the Lead is created.

    A contact with no email, such as one who only called or texted, never matches, so the scenario always creates a new Lead for them. This scenario can't prevent duplicates for those contacts.
  </Step>

  <Step title="Split into create and update">
    Add a **Router** after the API call, with two routes:

    * **Create**: filter `Body: totalSize` *Equal to* `0`.
    * **Update**: filter `Body: totalSize` *Greater than* `0`.
  </Step>

  <Step title="Create or update the Lead">
    On the **Create** route, add **Salesforce** → **Create a Record**, type **Lead**. On the **Update** route, add **Salesforce** → **Update a Record**, type **Lead**, with **ID** set to `Body: records[1]: Id`. Map the same fields on both:

    | Lead field | Make value |
    | - | - |
    | First Name | `{{join(remove(split(data.contact.name; " "); last(split(data.contact.name; " "))); " ")}}` |
    | Last Name | `{{ifempty(last(split(data.contact.name; " ")); ifempty(data.contact.email; "Unknown"))}}` |
    | Company | `{{ifempty(first(split(last(split(data.contact.email; "@")); ".")); "Unknown")}}` |
    | Email | `data.contact.email` |
    | Phone | `data.contact.phone` |
    | Lead Source | `TruAgents` |
    | Rating | `Hot` |
    | Description | `data.communication.subject`, `data.communication.preview`, and `data.communication._links.self`, on separate lines |

    Type the formulas with Make's function picker rather than pasting, so Make recognizes them. The First Name formula removes the last word from the name, so "Mary Ann Smith" gives "Mary Ann".
  </Step>

  <Step title="Answer TruAgents after Salesforce (recommended)">
    At the end of each route, add **Webhooks** → **Webhook response** with **Status** `200`.

    Then right-click each Salesforce module, choose **Add error handler**, and add a **Webhook response** with **Status** `503` there.

    With these, Make answers TruAgents only after Salesforce has responded. If Salesforce fails, TruAgents gets `503` and tries again later. Without them, Make answers `200` straight away and Salesforce errors only show in Make.
  </Step>

  <Step title="Turn it on">
    Save the scenario and turn it **ON** with **Immediately as data arrives** scheduling. Continue with [Step 3: test and go live](/automations/hot-leads-to-salesforce#step-3-test-and-go-live).
  </Step>
</Steps>

## Failures and retries with Make

* **With webhook responses** (step 6): a Salesforce failure returns `503` to TruAgents, which retries about every 5 to 10 minutes for up to 24 hours. TruAgents waits up to 30 seconds for an answer, which is plenty for two Salesforce calls.
* **Without webhook responses**: Make answers `200` on arrival. TruAgents shows the step as **Succeeded** and never retries, and errors only show in the scenario's **History**.
* Turn on Make's error notifications either way.
* If the scenario is off, Make queues incoming requests and processes them once the scenario is back on, up to Make's queue limit.

## Security

* The webhook address works like a password: anyone with it can create Leads through your scenario. Share it only in the **Send webhook** step. If it leaks, create a new webhook in Make and update the step.
* Don't add Salesforce credentials as headers on the **Send webhook** step. Make holds the Salesforce login.
* Keep the `replace` in the lookup query. Without it, an address that contains `'` can change the query, and the scenario can update a different Lead.

## Related pages

* [Send hot leads to Salesforce](/automations/hot-leads-to-salesforce)
* [Salesforce relay](/automations/salesforce-relay)
* [Salesforce with Zapier](/automations/salesforce-zapier)
* [Webhooks reference](/developers/webhooks)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.