Skip to main content

Integration

Salesforce and SendGrid Integration

Custom API integration triggering SendGrid emails from Salesforce events with Apex-driven dispatch, dynamic templates, and delivery tracking on contact records.

Salesforce
SendGrid

Integration

What This Integration Does

This integration triggers SendGrid email delivery from Salesforce events — opportunity stage changes, task completions, approval processes, and custom triggers — so that transactional and lifecycle emails are sent through SendGrid’s infrastructure with data pulled directly from your Salesforce records.

Salesforce has its own email capabilities, but they come with daily sending limits, limited template flexibility, and shared infrastructure that is not designed for high-volume transactional delivery. SendGrid is purpose-built for reliable email delivery at scale, with dedicated IPs, template versioning, and delivery analytics that Salesforce’s native email does not provide.

This integration connects the two so that Salesforce remains the source of truth for when and why an email should be sent, while SendGrid handles the how. The trigger logic lives in Salesforce — process builders, flows, Apex triggers, or platform events — and the delivery happens through SendGrid’s Mail Send API with dynamic templates populated from Salesforce record data.

The Workflow

A trigger fires in Salesforce. This could be an opportunity moving to “Closed Won”, a case being resolved, a task being completed, or any object event that should result in an email. The trigger creates a Platform Event record containing the email type identifier, the recipient’s email address, and the Salesforce record ID that holds the personalisation data.

The integration layer subscribes to these Platform Events. When an event arrives, the integration fetches the relevant Salesforce record (and any related records — account details, opportunity line items, case history) through the REST API. It assembles the personalisation payload by mapping Salesforce field values to the SendGrid template’s variable structure.

The integration then calls SendGrid’s Mail Send API, specifying the dynamic template ID and passing the personalisation object. SendGrid renders the template and delivers the email through your authenticated domain with the sending configuration you have set up — dedicated IP, IP pool assignment, tracking preferences.

After delivery, SendGrid’s Event Webhook reports delivery status, opens, clicks, bounces, and complaints back to a callback endpoint. The integration matches these events to the originating Salesforce record and creates Activity records or updates custom fields on the Contact, Lead, or related object. Bounces update a deliverability status field. Complaint events can trigger a Salesforce flow that suppresses the contact from future sends.

Before and After

Before: Salesforce sends emails through its built-in email capability, which counts against your daily org limit and shares infrastructure with every other Salesforce customer. Transactional emails like contract confirmations and onboarding welcome messages compete with internal workflow notifications for the same sending quota. Template customisation is constrained by Salesforce’s email template editor. Delivery analytics are basic — you know if an email was sent but not much about what happened after.

After: Transactional and lifecycle emails route through SendGrid with dedicated sending infrastructure, no daily limits beyond your SendGrid plan, and detailed delivery analytics. Salesforce controls the trigger logic and provides the data. SendGrid handles rendering and delivery. Bounce and complaint data flows back into Salesforce records so your contact data stays accurate. Your sales team sees email delivery and engagement status on the records they work with every day.

Who Needs This

This integration is for organisations that run their operations in Salesforce and need reliable, scalable email delivery for transactional or lifecycle messages. It is the right choice if:

  • You are hitting or approaching Salesforce’s daily email sending limits and need to offload transactional volume
  • You need dedicated sending infrastructure (dedicated IPs, authenticated domains) for transactional emails to protect deliverability
  • Your transactional email templates need richer formatting, dynamic content blocks, or versioning that Salesforce’s template editor cannot provide
  • You want delivery analytics (open rates, click tracking, bounce classification) per email type, visible on Salesforce records
  • Compliance requirements mandate that certain email types are sent through infrastructure on your own SendGrid account with full audit trails

How We Build This

We start by cataloguing the email types that should route through SendGrid and the Salesforce events that trigger them. For each email type, we define the trigger mechanism (Flow, Process Builder, Apex trigger, or Platform Event), the Salesforce records that provide personalisation data, and the SendGrid template that renders the email.

On the Salesforce side, we implement Platform Events as the integration boundary. Every trigger creates a lightweight event record with the email type, recipient, and source record ID. This decouples the trigger logic from the integration layer — your Salesforce admins can add new triggers without modifying the integration code.

The integration layer subscribes to the Platform Events via Salesforce’s CometD streaming or via a polling approach depending on volume and latency requirements. For each event, it fetches the required data through Salesforce’s composite API (which can retrieve a record and its related records in a single call) and maps the fields to SendGrid’s template variables.

SendGrid’s Mail Send v3 API handles delivery with API key authentication. Each email type maps to a SendGrid dynamic template. Templates use Handlebars syntax and support conditional sections, iteration over line items, and dynamic formatting. We configure sender authentication (SPF, DKIM, DMARC) on your sending domain within SendGrid.

The delivery feedback loop uses SendGrid’s Event Webhook. Events are received at a callback endpoint, matched to Salesforce records by a custom header or reference ID included in the original send, and written back to Salesforce as Activity records. Hard bounces and spam complaints update a deliverability status field that Salesforce automations can use for suppression.

Testing covers each email type end to end: the Salesforce trigger fires, the Platform Event is created, the integration processes the event, SendGrid delivers the email with the correct template and data, and delivery events flow back to the Salesforce record. We test with edge cases including missing data, bounced addresses, and high-volume concurrent triggers.

Start Sending Reliable Transactional Email From Salesforce

If your Salesforce-triggered emails are constrained by daily limits, basic templates, and shared infrastructure, your most important messages are at risk. We build the integration that gives Salesforce the delivery engine it lacks.

Get in touch to discuss your Salesforce and SendGrid integration.


Related pages:

Ready to Connect Your Systems?

We build custom API integrations that handle your data reliably at scale. No Zapier, no workarounds.

Discuss Your Integration View All Integrations