> ## 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.

# Sync Stigg data to Salesforce

The Stigg app for Salesforce provisions customers and subscriptions **from Salesforce into Stigg**. To send data in the opposite direction, **from Stigg into Salesforce**, use [Stigg Workflows](https://docs.stigg.io/documentation/workflows/overview.md) with a **Salesforce** action node.

With this setup, events that happen in Stigg (a trial starting, a customer exceeding their usage, entitlements changing) can create or update records in Salesforce, so your Sales and Customer Success teams see product signals right where they work.

> [!NOTE]
>
> The Salesforce → Stigg provisioning integration and the Stigg → Salesforce sync are independent. You can use either one on its own, or both together. The Stigg → Salesforce sync does not require the Stigg app for Salesforce to be installed.

## How it works

**1. Something happens in Stigg**

A [workflow trigger](https://docs.stigg.io/documentation/workflows/workflow-triggers.md) starts the workflow. Usually this is a [Stigg event](https://docs.stigg.io/api-and-sdks/api-reference/webhooks/events.md) such as `subscription.trial_started` or `entitlement.usage_exceeded`, or an **On a schedule** trigger for periodic syncs.

**2. The workflow decides what to sync**

Optional [condition](https://docs.stigg.io/documentation/workflows/workflow-conditions.md) nodes filter the events you care about (for example, only trials on your Pro plan), and [Stigg action](https://docs.stigg.io/documentation/workflows/workflow-actions.md#stigg-actions) nodes fetch any extra data you need (for example, the customer's current entitlements).

**3. The Salesforce node writes to Salesforce**

A **Salesforce** action node creates, updates or upserts a record in Salesforce: a Lead, Contact, Account, Opportunity, Task, or any custom object.

## Example use cases

| Use case | Trigger | What gets written to Salesforce |
| - | - | - |
| [Trials on a higher tier](https://docs.stigg.io/documentation/native-integrations/crm/salesforce/stigg-to-salesforce-examples.md#create-a-lead-when-a-customer-starts-a-trial-on-a-higher-tier) | `subscription.trial_started` | A Lead (or an update to the existing Account) so Sales can help the customer convert |
| [Usage exceeds a limit](https://docs.stigg.io/documentation/native-integrations/crm/salesforce/stigg-to-salesforce-examples.md#create-a-task-when-a-customer-exceeds-their-usage) | `entitlement.usage_exceeded` | A Task for the account owner so they can reach out with an upsell |
| [Entitlement sync](https://docs.stigg.io/documentation/native-integrations/crm/salesforce/stigg-to-salesforce-examples.md#sync-entitlements-to-the-salesforce-account) | `entitlements.updated` | The customer's current entitlements on the Account record |
| [Usage sync](https://docs.stigg.io/documentation/native-integrations/crm/salesforce/stigg-to-salesforce-examples.md#sync-usage-to-salesforce-on-a-schedule) | Schedule | The customer's current usage of key features on the Account record |

## Prerequisites

* Access to [Stigg Workflows](https://docs.stigg.io/documentation/workflows/overview.md). Workflows are currently in beta; to request access, contact [Stigg Support](mailto:support@stigg.io).
* A Salesforce edition with API access, such as Enterprise, Unlimited, or Developer Edition.
* A Salesforce user that can authorize the connection and has **API Enabled** on their profile or permission set, plus read and write access to the objects your workflows will update.
* A Salesforce admin that can create an External Client App, and any custom fields you want to sync Stigg data into.

## Step 1: Connect Salesforce to Stigg Workflows

The Salesforce node authenticates with a Salesforce credential. Credentials are stored per Stigg environment, so you'll need to create one in each environment (for example, once for development and once for production). See [Managing credentials](https://docs.stigg.io/documentation/workflows/managing-workflow-credentials.md).

**1. Start creating the credential in Stigg**

In the [Stigg app](https://app.stigg.io), go to **Workflows** and open the **Credentials** tab. Create a new credential and select **Salesforce OAuth2 API**.

You can also do this the first time you add a Salesforce node to a workflow: select **Create new credential** in the node's credential dropdown.

Copy the URL shown at the top of the credential dialog. This is the OAuth callback URL, and you'll need it in the next step. Keep the dialog open.

**2. Create an External Client App in Salesforce**

In Salesforce, go to **Setup**, search for **External Client App Manager**, and click **New External Client App**.

Under **Basic Information**, enter a name (for example, `Stigg Workflows`) and a contact email, and set **Distribution State** to **Local**.

Under **API (Enable OAuth Settings)**, select **Enable OAuth** and set:

| Field | Value |
| - | - |
| **Callback URL** | The callback URL you copied from Stigg |
| **Selected OAuth Scopes** | `Manage user data via APIs (api)` and `Perform requests at any time (refresh_token, offline_access)` |

Leave the default **Security** settings, including **Require Proof Key for Code Exchange (PKCE)**, as they are. Then click **Create**.

> [!WARNING]
>
> Salesforce pre-fills the callback URL with `https://example.com`. Replace it with the URL from Stigg, or authorization fails with a `redirect_uri_mismatch` error.

**3. Copy the Consumer Key and Secret**

On the app's page, open the **Settings** tab, expand **OAuth Settings**, and click **Consumer Key and Secret**. Salesforce emails you a verification code before it shows them.

Use the **Copy** buttons to copy the **Consumer Key** and **Consumer Secret**. The key contains look-alike characters, so copying it by hand can introduce errors.

**4. Finish the credential in Stigg**

Back in the Stigg credential dialog, set:

| Field | Value |
| - | - |
| **Client ID** | The Consumer Key from Salesforce |
| **Client Secret** | The Consumer Secret from Salesforce |
| **Environment Type** | `Production` for production and Developer Edition orgs, or `Sandbox` for Salesforce sandboxes |

Click **Save**, then click **Connect my account**. Sign in to Salesforce with the user the workflow should act as, and click **Allow**. Records created by the workflow will show this user as their creator.

> [!TIP]
>
> For production, authorize the credential with a dedicated Salesforce integration user rather than a personal account. If that person leaves the company or their password changes, a credential tied to their account stops working.

> [!NOTE]
>
> Depending on your org, some of the app's **Security** settings are selected and locked, with the message *To change this required setting, contact Support*. These can include PKCE, refresh token rotation, and a 30-day limit on idle refresh tokens. With the 30-day limit, the connection expires if no workflow uses it for 30 days, and you need to reconnect the credential in Stigg.

### Troubleshooting the connection

| Error | Cause | Fix |
| - | - | - |
| `invalid_client_id` | Salesforce doesn't recognize the Client ID. Either the app is new and not active yet, or the key was copied incorrectly. | Wait up to 10 minutes after creating the app. If the error persists, copy the Consumer Key again with the **Copy** button and check for spaces at either end. |
| `redirect_uri_mismatch` | The app's callback URL doesn't exactly match the URL in the Stigg credential dialog. | Edit the app's **OAuth Settings** and paste the URL from Stigg, with no trailing slash or extra spaces. Changes can take up to 10 minutes to apply. |

## Step 2: Prepare Salesforce to receive Stigg data

Decide where Stigg data should live in Salesforce, and create any custom fields you need before building the workflow. Common choices are:

| Object | Typical fields | Used for |
| - | - | - |
| **Lead** | Stigg Customer ID, Stigg Plan, Trial End Date | Self-serve customers that don't exist in Salesforce yet |
| **Account** | Stigg Plan, Stigg Entitlements, usage fields per feature | Customers that are already in Salesforce |
| **Task** | None (standard fields are enough) | Asking a rep to follow up |

> [!NOTE]
>
> If you also use the Salesforce → Stigg provisioning integration, the Stigg app for Salesforce already adds a **Stigg Customer ID** field to the Account object. Reuse it to look up Accounts from your workflows.

### Use the Stigg customer ID as an External ID

Workflows can run more than once for the same customer (for example, a customer can start a second trial, or an event can be retried). To avoid creating duplicate records, add a **Stigg Customer ID** text field to every object you create records on, and mark it as **Unique** and **External ID** in Salesforce.

With an External ID field in place, the Salesforce node can use the **Create or Update** operation, which updates the existing record if one with the same Stigg customer ID exists, and creates a new one otherwise.

### Create the custom fields

Create each field on the object it belongs to, for example **Account** or **Lead**:

**1. Open the object's fields**

In Salesforce **Setup**, click **Object Manager**, select the object, then select **Fields & Relationships** and click **New**.

**2. Choose the field type**

Select the data type, and click **Next**. Use **Text** for IDs, names and statuses, **Date/Time** for dates, **Number** for usage values, and **Text Area (Long)** for longer summaries such as entitlements.

**3. Enter the field details**

Enter the **Field Label**, for example `Stigg Customer ID`, and a **Length** of 255 for text fields. Keep the **Field Name** that Salesforce fills in, because workflows refer to the field by its API name (for example, `Stigg_Customer_ID__c`).

For the **Stigg Customer ID** field, also select **Unique** with **Treat "ABC" and "abc" as different values (case sensitive)**, and select **External ID**. Click **Next**.

**4. Set field-level security**

New fields are hidden from all profiles unless you select them here. Select **Visible** for the profile of the user you connected in [Step 1](#step-1-connect-salesforce-to-stigg-workflows), and leave **Read-Only** cleared. Also select **Visible** for the profiles your Sales team uses, so they can see the field. Click **Next**.

**5. Add the field to page layouts**

Keep the object's default layout selected, and click **Save & New** to add the next field, or **Save** after the last one.

> [!NOTE]
>
> If the connected user can't edit a field, Salesforce rejects the workflow's request. If a sync fails with a field access error, check the field's field-level security.

> [!TIP]
>
> Use **Text** rather than **Picklist** for fields that hold Stigg values such as subscription statuses. A picklist rejects any value that you haven't added to it, such as `IN_TRIAL` or `PAYMENT_PENDING`.

> [!TIP]
>
> To find a field's API name (for example, `Stigg_Customer_ID__c`), go to **Setup** > **Object Manager**, select the object, and open **Fields & Relationships**. Fields that come from the Stigg app for Salesforce managed package may include a namespace prefix.

## Step 3: Build the workflow

**1. Create a workflow and add a trigger**

In the [Stigg app](https://app.stigg.io), go to **Workflows** and click **Start from scratch** (see [Workflow creation](https://docs.stigg.io/documentation/workflows/workflow-creation.md)).

Add a **Stigg Event Trigger**. In **Credential to connect with**, select your Stigg API key credential (see [Managing credentials](https://docs.stigg.io/documentation/workflows/managing-workflow-credentials.md)). Under **Events**, select the event to react to, for example **Subscription Trial Started** (`subscription.trial_started`).

For periodic syncs, use the **On a schedule** trigger instead.

**2. Add sample data**

In the trigger's **Output** panel, click **set mock data** and paste a sample event payload. Later nodes can then reference the event's fields without waiting for a real event. See [Webhook events](https://docs.stigg.io/api-and-sdks/api-reference/webhooks/events.md) for the payload of each event.

**3. Filter the events you care about**

Add an **If** node to continue only for relevant events. For example, to sync only trials on your Pro plan, set the condition to:

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

To fill in **value1**, drag the field from the **Input** panel, or type the expression. See [Expressions](https://docs.stigg.io/documentation/workflows/workflow-expressions.md) for more examples.

**4. Add a Salesforce node**

Click **+** on the **true** branch of the condition, search for **Salesforce**, and select the action you need, for example **Create or update a lead**.

Select the Salesforce credential you created in [Step 1](#step-1-connect-salesforce-to-stigg-workflows). The node fills in **Resource** and **Operation** from the action you picked.

**5. Map Stigg data to Salesforce fields**

Fill in the node's fields with values from the trigger. You can drag fields from the input panel on the left into the node's parameters, or type an expression, for example `{{ $json.customer.email }}`.

Under **Additional Fields** > **Custom Fields**, map values into your custom fields by their API name.

For **Create or Update** operations, **Match Against** lists the External ID fields on the Salesforce object. The list loads from Salesforce, so the field must already exist and the credential must be connected.

**6. Test the workflow**

Send a test event from the trigger node (see [Manual trigger & test events](https://docs.stigg.io/documentation/workflows/workflow-creation.md#manual-trigger--test-events)), or perform the action in Stigg (for example, start a trial for a test customer).

Check that the record was created or updated in Salesforce as expected, and review the run in the [workflow execution history](https://docs.stigg.io/documentation/workflows/workflow-execution-history.md).

**7. Activate the workflow**

Once the workflow behaves as expected, activate it. From this point on, it runs every time the trigger fires.

## Matching Stigg customers to Salesforce records

Before updating an existing record, the workflow needs to know which Salesforce record belongs to the Stigg customer. Use one of the following approaches:

| Approach | When to use it | How |
| - | - | - |
| **Salesforce ID on the Stigg customer** | Customers that were provisioned from Salesforce through the Stigg app for Salesforce | Subscription events include `customer.salesforceId`, which holds the ID of the Salesforce Account the customer was provisioned from. Use it as the record ID in an **Update** operation. |
| **External ID upsert** | You create records from Stigg (for example, Leads for self-serve customers) | Use **Create or Update** with your **Stigg Customer ID** External ID field and `{{ $json.customer.id }}` as its value. |
| **SOQL lookup** | Events that don't include the Salesforce ID, such as `entitlement.usage_exceeded` | Add a Salesforce **Search** node that runs a SOQL query on the Stigg Customer ID field, then use the returned record `Id` in the next node. |

Example SOQL lookup:

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

> [!NOTE]
>
> If a lookup returns no records, the nodes after it won't run for that event. If you want to handle customers that aren't in Salesforce yet (for example, by creating a Lead instead), enable **Always Output Data** in the Search node's settings and add an **If** node that checks whether an `Id` was returned.

## Things to keep in mind

* **Error handling**: if Salesforce rejects a request (for example, because a required field is missing or the credential expired), the workflow run fails and shows up in the execution history. See [Error handling](https://docs.stigg.io/documentation/workflows/error-handling.md) to get notified about failures.
* **Required fields**: Salesforce enforces required fields and validation rules on records created through the API. For example, a Lead requires **Last Name** and **Company**.
* **API limits**: every Salesforce node call counts toward your org's daily API request limit. For high-volume events, filter early in the workflow, and prefer scheduled syncs over syncing on every event.
* **Environments**: workflows and credentials are scoped to a Stigg environment. Point your development environment at a Salesforce sandbox and your production environment at your production org.

## Next steps

> [card] [Examples](https://docs.stigg.io/documentation/native-integrations/crm/salesforce/stigg-to-salesforce-examples.md)
>
> Step-by-step recipes for common Stigg → Salesforce syncs.

> [card] [Workflow actions](https://docs.stigg.io/documentation/workflows/workflow-actions.md)
>
> All Stigg actions you can combine with the Salesforce node.


## Related topics

- [Overview](https://docs.stigg.io/documentation/workflows/overview.md)
- [Salesforce](https://docs.stigg.io/documentation/native-integrations/crm/salesforce/salesforce.md)
- [Stigg to Salesforce examples](https://docs.stigg.io/documentation/native-integrations/crm/salesforce/stigg-to-salesforce-examples.md)
- [Welcome to Stigg](https://docs.stigg.io/documentation/getting-started/welcome-to-stigg.md)
- [Data residency and PII](https://docs.stigg.io/documentation/security-compliance/data-residency-and-pii.md)


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