Back to APIs

Salesforce

salesforce.com

Automate CRM operations and data synchronization.

Using the Salesforce API with Trigger.dev

You can use Trigger.dev with any existing Node SDK or even just using fetch. Using io.runTask makes your Salesforce background job resumable and appear in our dashboard.

Use io.runTask() and the official SDK or fetch.

Use our HTTP endpoint to subscribe to webhooks

Example code using Salesforce

Below are some working code examples of how you can use Salesforce with Trigger.dev. These samples are open source and maintained by the community, you can copy and paste them into your own projects.

1
import { TriggerClient, verifyRequestSignature } from "@trigger.dev/sdk";
2
3
// Create an HTTP Endpoint to listen to Salesforce webhooks
4
// (This will create the endpoint URL and Secret on the `trigger.dev` dashboard)
5
// Salesforce does not have built-in webhooks. `Object Triggers` and `Callouts` can be used to simulate them.
6
// Setup the `Trigger` on the required Object. The `Callout` has to be marked async in order to work.
7
// The `Callout` has to execute an HTTP request to the endpoint URL on the dashboard with the necessary data.
8
// It has to compute a Hmac sign for the webhook body using the Secret from `trigger.dev` dashboard.
9
// Set the `SF_WEBHOOK_SIGNING_SECRET` (Secret) in the .env file.
10
const salesforce = client.defineHttpEndpoint({
11
id: "salesforce",
12
source: "salesforce.com",
13
icon: "salesforce",
14
verify: async (request) => {
15
return await verifyRequestSignature({
16
request,
17
headerName: "X-SF-Signature-256",
18
secret: process.env.SF_WEBHOOK_SIGNING_SECRET!,
19
algorithm: "sha256",
20
});
21
},
22
});
23
24
client.defineJob({
25
id: "http-salesforce",
26
name: "HTTP Salesforce",
27
version: "1.0.0",
28
enabled: true,
29
// Create a trigger from the HTTP endpoint
30
trigger: salesforce.onRequest(),
31
run: async (request, io, ctx) => {
32
const body = await request.json();
33
await io.logger.info(`Body`, body);
34
},
35
});