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

# Stigg to Salesforce examples

The examples below show how to sync common product signals from Stigg into Salesforce. Each one assumes you've already [connected Salesforce to Stigg Workflows](https://docs.stigg.io/documentation/native-integrations/crm/salesforce/stigg-to-salesforce.md#step-1-connect-salesforce-to-stigg-workflows).

Field names such as `Stigg_Customer_ID__c` are examples. Replace them with the API names of the fields in your Salesforce org, and replace plan and feature IDs with the IDs from your Stigg product catalog.

> [!TIP]
>
> Expressions such as `{{ $json.customer.id }}` reference data from the previous node. The easiest way to get them right is to set mock data on the trigger, then drag fields from each node's **Input** panel into its parameters.

## Create a Lead when a customer starts a trial on a higher tier

**Goal:** when a self-serve customer starts a trial of your Pro plan, create a Lead in Salesforce so a sales rep can help them convert.

**Salesforce setup:** on the **Lead** object, add a **Stigg Customer ID** text field marked as **Unique** and **External ID**, plus optional **Stigg Plan** (text) and **Trial End Date** (date) fields.

**1. Trigger: Trial started**

Add a **Stigg Event Trigger** and under **Events** select **Subscription Trial Started** (`subscription.trial_started`).

**2. Condition: only trials on the Pro plan**

Add an **If** node with the condition:

| value1 | Operator | value2 |
| - | - | - |
| `{{ $json.plan.id }}` | **is equal to** | `plan-pro` |

**3. Salesforce: create or update the Lead**

On the **true** branch, add a **Salesforce** node with **Resource** set to **Lead** and **Operation** set to **Create or Update**, and configure:

| Field | Value |
| - | - |
| **Match Against** | `Stigg_Customer_ID__c` |
| **Value to Match** | `{{ $json.customer.id }}` |
| **Company** | `{{ $json.customer.name \|\| $json.customer.id }}` |
| **Last Name** | `{{ $json.customer.name \|\| "Unknown" }}` |
| **Email** (additional field) | `{{ $json.customer.email }}` |
| **Lead Source Name or ID** (additional field) | A value from your org's Lead Source picklist, for example `Web`. To use a value such as `Product trial`, add it to the picklist in Salesforce first. |
| **Custom Fields** | `Stigg_Plan__c` = `{{ $json.plan.name }}`, `Trial_End_Date__c` = `{{ $json.trialEndDate }}` |

**Variation:** if the customer already exists in Salesforce as an Account (`customer.salesforceId` is set), update the Account instead of creating a Lead. Add an **If** node with `{{ $json.customer.salesforceId }}` **is not empty**, and on the **true** branch use **Account** > **Update** with `{{ $json.customer.salesforceId }}` as the Account ID.

## Create a Task when a customer exceeds their usage

**Goal:** when a customer exceeds the limit of a metered feature, create a follow-up Task for the Account owner so they can offer an upgrade.

**Salesforce setup:** the **Account** object has a **Stigg Customer ID** field. If you use the Salesforce → Stigg provisioning integration, this field already exists and is filled in automatically.

**1. Trigger: Entitlement usage exceeded**

Add a **Stigg Event Trigger** and under **Events** select **Entitlement Usage Exceeded** (`entitlement.usage_exceeded`).

Optionally, under **Usage Exceeded Thresholds**, click **Add Threshold** to choose which usage thresholds start the workflow.

**2. Condition: only the feature you care about**

Add an **If** node that keeps only events for the relevant feature:

| value1 | Operator | value2 |
| - | - | - |
| `{{ $json.feature.id }}` | **is equal to** | `feature-api-calls` |

**3. Salesforce: find the Account**

Add a **Salesforce** node with **Resource** set to **Search** and **Operation** set to **Query**, with the query:

```sql theme={null}
SELECT Id, OwnerId FROM Account WHERE Stigg_Customer_ID__c = '{{ $json.customer.id }}' LIMIT 1
```

**4. Salesforce: create the Task**

Add another **Salesforce** node with **Resource** set to **Task** and **Operation** set to **Create**, and configure:

| Field | Value |
| - | - |
| **Status** | `Not Started` |
| **Subject** (additional field) | `Upsell opportunity: {{ $('If').item.json.customer.name }} exceeded {{ $('If').item.json.feature.name }}` |
| **What ID** (additional field) | `{{ $json.Id }}` |
| **Owner** (additional field) | `{{ $json.OwnerId }}` |
| **Description** (additional field) | `Usage: {{ $('If').item.json.currentUsage }} of {{ $('If').item.json.usageLimit }} {{ $('If').item.json.feature.units }}` |

Because this node runs after the Search node, `$json` holds the Account returned by the query. Use `$('If').item.json` to reference the original event data. Replace `If` with the name of your condition node if you renamed it.

> [!NOTE]
>
> `entitlement.usage_exceeded` fires once each time a customer crosses a usage threshold, so the same customer can generate a new Task in each usage period. To limit noise, set **Usage Exceeded Thresholds** on the trigger, add a condition on `{{ $json.thresholdPercentage }}`, or create an Opportunity with **Create or Update** instead of a Task.

## Sync entitlements to the Salesforce Account

**Goal:** keep a summary of the customer's current entitlements on their Salesforce Account, so reps can see what the customer has access to without leaving Salesforce.

**Salesforce setup:** on the **Account** object, add a **Stigg Entitlements** field of type **Long Text Area**.

**1. Trigger: Entitlements updated**

Add a **Stigg Event Trigger** and under **Events** select **Entitlements Updated** (`entitlements.updated`). This event fires whenever a customer's entitlements change, for example after a subscription is created, upgraded or canceled, or a promotional entitlement is granted.

**2. Format the entitlements**

Add a **Code** node in JavaScript that turns the entitlements array into readable text:

```js theme={null}
const event = $input.first().json;
const lines = event.entitlements.map((e) => {
  const limit = e.hasUnlimitedUsage ? 'Unlimited' : (e.usageLimit ?? 'Included');
  return `${e.feature.name}: ${limit}`;
});

return [{ json: { customerId: event.customer.id, summary: lines.join('\n') } }];
```

**3. Salesforce: find the Account**

Add a **Salesforce** node with **Resource** set to **Search** and **Operation** set to **Query**:

```sql theme={null}
SELECT Id FROM Account WHERE Stigg_Customer_ID__c = '{{ $json.customerId }}' LIMIT 1
```

**4. Salesforce: update the Account**

Add a **Salesforce** node with **Resource** set to **Account** and **Operation** set to **Update**:

| Field | Value |
| - | - |
| **Account ID** | `{{ $json.Id }}` |
| **Custom Fields** | `Stigg_Entitlements__c` = `{{ $('Code').item.json.summary }}` |

## Sync usage to Salesforce on a schedule

**Goal:** once a day, write each customer's current usage of a key feature to their Salesforce Account, so reps can spot accounts that are close to their limits.

Usage changes constantly, so syncing it on every change would quickly use up your Salesforce API limits. A scheduled sync keeps Salesforce up to date with a predictable number of API calls.

**Salesforce setup:** on the **Account** object, add **API Calls Usage** (number), **API Calls Limit** (number) and **Usage Synced At** (date/time) fields.

**1. Trigger: On a schedule**

Add an **On a schedule** trigger that runs once a day, for example at 02:00.

**2. Salesforce: get the Accounts to sync**

Add a **Salesforce** node with **Resource** set to **Search** and **Operation** set to **Query**:

```sql theme={null}
SELECT Id, Stigg_Customer_ID__c FROM Account WHERE Stigg_Customer_ID__c != null
```

The node outputs one item per Account. The nodes that follow run once for each item.

**3. Stigg: get the customer's usage**

Add a **Stigg** node with the **Get entitlement to a feature** action, and set:

| Field | Value |
| - | - |
| **Customer ID** | `{{ $json.Stigg_Customer_ID__c }}` |
| **Feature ID** | `feature-api-calls` |

**4. Salesforce: update the Account**

Add a **Salesforce** node with **Resource** set to **Account** and **Operation** set to **Update**:

| Field | Value |
| - | - |
| **Account ID** | `{{ $('Salesforce').item.json.Id }}` |
| **Custom Fields** | `API_Calls_Usage__c` = `{{ $json.currentUsage }}`, `API_Calls_Limit__c` = `{{ $json.usageLimit }}`, `Usage_Synced_At__c` = `{{ $now.toISO() }}` |

Replace `Salesforce` in `$('Salesforce')` with the name of the Search node if you renamed it.

> [!NOTE]
>
> Each Account in the query results makes one Stigg call and one Salesforce update call. If you have many Accounts, narrow the query (for example, to Accounts with an active opportunity), or add a **Loop Over Items** node to process Accounts in batches.


## Related topics

- [Sync Stigg data to Salesforce](https://docs.stigg.io/documentation/native-integrations/crm/salesforce/stigg-to-salesforce.md)
- [Supported actions](https://docs.stigg.io/documentation/native-integrations/crm/salesforce/salesforce-supported-actions.md)
- [Set up the integration](https://docs.stigg.io/documentation/native-integrations/crm/salesforce/salesforce-setup.md)
- [Salesforce](https://docs.stigg.io/documentation/native-integrations/crm/salesforce/salesforce.md)
- [Activity log](https://docs.stigg.io/documentation/managing-your-account/activity-log.md)


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