Skip to main content
New tool CRON Expression Builder — preview next run times before you schedule Apex. Open the builder →
Diagram illustrating the Salesforce Streaming API architecture for real-time data notifications
Integration

Salesforce Streaming API - Mechanisms and Real-Time Data

Constant polling burns through your API limits. This guide walks the four Salesforce Streaming API mechanisms and why Platform Events are where most serious real-time integrations end up.

The short answer

The Salesforce Streaming API is an event-driven mechanism that pushes real-time data to clients so daily REST polling limits do not get exhausted. It supports four streaming mechanisms: PushTopics, Platform Events, Change Data Capture (CDC), and Generic Streaming. All of them run on CometD and the Bayeux protocol to hold persistent connections open.

Key takeaways Use Change Data Capture for replication to external databases: it streams record create, update, delete, and undelete deltas for you. Use Platform Events for decoupled, fire-and-forget messages that drive custom business logic from Apex, Flow, or an external system. Implement ReplayID logic in your subscriber clients so a dropped connection does not cost you messages. Make subscriber systems idempotent so a duplicate delivery does not create data discrepancies.

How the Salesforce Streaming API saves your integration limits

Ever had a client ask for a dashboard that updates the second a deal closes? You could set up a REST API that polls Salesforce every five seconds, but your API limits will scream at you. That's where the Salesforce Streaming API comes in. Salesforce pushes data to you the moment something happens, instead of you constantly asking whether there's an update.

I've seen too many teams burn through their daily limits because they didn't want to deal with the learning curve of event-driven architecture. Once it clicks, though, you'll never go back to basic polling for real-time needs. This is what a Salesforce API integration that scales without breaking the bank looks like.

The four flavors of the Salesforce Streaming API

Salesforce gives us four different ways to get these notifications, and picking the wrong one is a classic rookie mistake. Here's how each behaves in the wild.

1. PushTopic streaming

This is the "old school" way of doing things, but it still has its place. You write a SOQL query and tell Salesforce, "Hey, if any record that matches this query changes, let me know." It's declarative and you can filter exactly which fields you care about.

It isn't the most reliable choice for heavy enterprise workloads, though. I usually only recommend PushTopics for simple UI updates where it isn't the end of the world if a message gets dropped once in a blue moon. Easy to set up, but it doesn't have the same "oomph" as the newer tools.

2. Platform Events

If you're building anything serious, you'll probably end up here. Platform Events are the gold standard for modern Salesforce development. They're much more flexible because they aren't strictly tied to a single record update. You can fire a Platform Event from a Flow, Apex, or even an external system.

Pro tip: if you're weighing this against older tech, the guide on Platform Events vs Outbound Messages will save you a lot of architectural headaches later on.

One thing that trips people up is that Platform Events are "fire and forget." Once you send it, Salesforce handles the delivery. It's more reliable than PushTopics because it supports replay IDs, so your subscriber can catch up if it goes offline for a minute.

An architecture diagram showing Salesforce data objects flowing into a central event bus and streaming out to external applications.

Records flow into the event bus, and the bus streams out to whatever is subscribed.

3. Change Data Capture (CDC)

CDC is like PushTopic's cooler, more organized younger brother. Instead of writing queries, you flip a switch for an object (Account or Opportunity, say). Salesforce then automatically streams every single create, update, delete, or undelete event.

I love using CDC for data replication. If you need to keep an external SQL database in sync with Salesforce, start here. It's especially useful when managing large data volumes because it only sends the changes, not the whole record every time. It keeps the noise down and the speed up.

4. Generic Streaming

You won't use this one often. Generic streaming lets you send custom text strings that aren't tied to Salesforce records at all. Think of a simple chat window or a status notification. It's lightweight, but since Platform Events came out, most of the reasons to reach for Generic Streaming have kind of disappeared.

How the connection actually stays alive

So how does the Salesforce Streaming API keep that connection open without timing out? It uses the Bayeux protocol and CometD. Think of it as a "long-lived" request: the client asks for data, and Salesforce holds onto that request until it actually has something to say.

Don't forget about authentication. You're still using OAuth tokens here. If your session expires, your stream dies. I've spent hours debugging a "broken" integration only to realize the integration user's password had expired or the token wasn't refreshed. Don't be that person.

Key takeaways for developers

  • Use CDC for syncing data to external databases or keeping caches fresh.
  • Use Platform Events for custom business logic and complex workflows between systems.
  • Always implement ReplayID logic. Connections drop. If you don't use the ReplayID, you'll lose data.
  • Watch your limits. Even though streaming is efficient, Salesforce still caps the number of events you can send in a 24-hour window.
  • Stay idempotent, which is a fancy way of saying your system should handle receiving the same message twice without breaking things.

A quick code reality check

Most people use a library like CometD in JavaScript to listen to these streams. Here's a tiny snippet of what a PushTopic subscription looks like in practice. It's not as scary as it looks, but you've got to get the handshake right first.

// This is the basic handshake and subscription flow
cometd.configure({
  url: 'https://your-instance.salesforce.com/cometd/60.0',
  requestHeaders: { Authorization: 'Bearer ' + sessionID }
});

cometd.handshake(function(reply) {
  if (reply.successful) {
    // We are in! Now listen to the channel
    cometd.subscribe('/topic/NewLeads', function(message) {
      console.log('Got a new lead: ', message.data.sobject.Name);
    });
  }
});

The Salesforce Streaming API is about making your apps feel fast and responsive. No user wants to hit a refresh button in 2026. Whether you go with Platform Events or CDC, think hard about how the system recovers when the internet inevitably hiccups. Get that right and nobody ever notices the plumbing.

Frequently asked questions

What are the four types of Salesforce Streaming API?

Salesforce provides PushTopic streaming, Platform Events, Change Data Capture (CDC), and Generic Streaming. They cover different architectural needs: query-based notifications, automated data deltas, and custom event payloads.

When should you use Change Data Capture instead of PushTopics?

Change Data Capture is the better fit for replicating data to external databases, because it automatically streams create, update, delete, and undelete operations as delta changes. PushTopics need a SOQL query and suit simpler UI updates where an occasional dropped message is acceptable.

How does the Salesforce Streaming API maintain real-time connections?

The Streaming API uses the Bayeux protocol and CometD to open long-lived requests, and Salesforce holds the connection open until it has new data to push. Connections need valid OAuth authentication and fail if the session expires or tokens are not refreshed.

Why should you use Platform Events over PushTopics?

Platform Events are more flexible: you can fire them from Apex, Flow, or an external system without tying them to a SOQL query. They are also fire-and-forget, and they support Replay IDs so a subscriber can catch up on events it missed while offline.

Newsletter

One email every Tuesday

New guides, tool updates, and the release-note changes that break things.

No spam. Unsubscribe in one click.

Comments

Loading comments...

Leave a Comment