All articles

Platform

Change Data Capture vs platform events: choosing what to publish in Salesforce

Change Data Capture and platform events ride the same event bus, so teams pick one by habit and regret it later. One mirrors your data model automatically; the other is a message contract you own. A practitioner walk through the real differences, the enriched-fields trap, the Apex change event trigger, and which to reach for.

A team wires an external order system to Salesforce and reaches for Change Data Capture, because it is one checkbox. Six months later every subscriber breaks the day someone adds a required field to the Order object. The event changed because the object changed, and nobody downstream agreed to that.

That failure is the whole decision in miniature. Change Data Capture and platform events are delivered over the same event bus, with the same replay mechanics and the same at-least-once promise, so they look interchangeable. They are not. Change Data Capture mirrors your data model and gives you no say over the payload. A platform event is a contract you design, and the schema changes only when you change it.

My rule, up front. If the consumer wants to know “this record changed, keep your copy in sync,” use Change Data Capture. If the consumer wants to know “this business thing happened, here is exactly what it needs,” define a platform event. Reach for the one whose shape matches the message, not the one that is faster to turn on.

Change Data Capture mirrors the object

Change Data Capture publishes a change event automatically whenever a tracked record is created, updated, deleted, or undeleted. You select the objects in Setup, and from then on the platform emits events with no publish code anywhere. The schema follows the object, so every field is potentially in scope.

Each event carries a header, the ChangeEventHeader, and that header is where the useful detail lives.

trigger OrderChangeTrigger on Order__ChangeEvent (after insert) {
    for (Order__ChangeEvent evt : Trigger.new) {
        EventBus.ChangeEventHeader header = evt.ChangeEventHeader;

        // what happened, and to which records
        String op = header.getChangeType();              // CREATE / UPDATE / DELETE / UNDELETE
        List<String> ids = header.getRecordIds();        // bulk: many records per event
        List<String> changed = header.getChangedFields(); // only the fields that moved

        // changed values are readable off the event itself
        if (op == 'UPDATE' && changed.contains('Status__c')) {
            // react to the status change
        }
    }
}

Two things in that trigger decide how you write the consumer. The event is bulk, so getRecordIds() returns many Ids for a single change that touched many rows, and your code has to loop. And getChangedFields() lists only what moved on an update, so a downstream mirror can apply a patch instead of a full overwrite.

A change event trigger does not run inline with the transaction that caused it. It fires asynchronously after commit, as the Automated Process user, in batches of up to 2,000 change events per execution. That has consequences: the running user is not your user, Trigger.old does not exist, and ordering across entities is not guaranteed.

Design the consumer to be stateless and idempotent, the same discipline a retry-safe integration needs anywhere.

The enriched-fields trap

The most common Change Data Capture mistake is assuming an update event carries the fields you care about. It carries only the ones that changed. If a downstream rule keys off Account.Owner but the owner did not change on this update, that field is simply absent from the event.

The fix is enriched fields, and it comes with rules worth knowing before you rely on it. Salesforce includes enriched fields in update and delete events only, not in create or undelete events, because those already carry every populated field.

You can enrich up to ten fields per channel member, and only on a channel that spans multiple entities, such as the standard /data/ChangeEvents channel or a custom channel, never on a single-entity channel like /data/AccountChangeEvent. Empty enriched values are dropped in CometD clients and arrive as null in Pub/Sub API clients, and a relationship field gives you the related record’s Id, not its details.

The catch underneath all of that: enrichment widens the payload, so client code that assumed “only changed fields are present” has to be updated when you turn it on. More than one integration has broken not from a missing field but from an unexpected one.

Platform events are a contract you own

A platform event is a message you define. You create the event like a custom object, give it exactly the fields the consumer needs, and publish it deliberately from Apex, Flow, or the API.

// one event, your schema, published on purpose
Order_Shipped__e shipped = new Order_Shipped__e(
    Order_Number__c = o.OrderNumber,
    Carrier__c      = 'UPS',
    Tracking__c     = trackingId,
    Shipped_At__c   = System.now()
);
Database.SaveResult sr = EventBus.publish(shipped);

Nothing about Order_Shipped__e moves when someone edits the Order object. The producer decides when it fires and what it means, and the consumer codes against a stable shape. That decoupling is the reason to prefer a platform event for a genuine integration message: the two systems share a contract, not a data model.

Platform events also publish two ways, and the choice matters. Publish After Commit fires only once the Apex transaction commits, so a rollback never emits a phantom event. Publish Immediately fires regardless of the outcome, which suits a logging or audit signal you want even when the transaction fails. Change Data Capture gives you neither knob; it always reflects a committed change.

One throughput detail settles some designs on its own. High-volume platform events support parallel Apex subscription, so a backlog can be worked by multiple concurrent subscribers. Change event triggers cannot do that. If you expect bursts that one serial subscriber cannot drain, that alone can point you at a platform event.

What they share, and the limit that bites

Both ride the same event bus, and the bus is not a database.

Events are retained for 72 hours. A subscriber tracks its position with a replay Id and can resume from where it left off, but anything older than the window is gone. So replay covers a short outage, a redeploy, a subscriber restart. It does not cover a consumer that was down for a long weekend.

For that you still need a reconciliation job that reads the current state and repairs the drift, the same way a bulk extract backfills what streaming missed.

Delivery is at-least-once, which means duplicates are possible on both. Design every consumer to be idempotent, keyed on the record Id and a change marker, so a redelivered event is a no-op rather than a double-apply. This is the same property that makes an idempotent agent action safe to retry, and it is non-negotiable here too.

The limit teams trip over is that delivery is a shared allocation. Change Data Capture and all of your platform events draw from the same edition-based daily delivery budget. A chatty object tracked “just in case” can burn the allocation that a business-critical event needed, so track what a consumer subscribes to, not everything.

The decision, in four questions

  1. Is the message “a record changed, stay in sync,” or “this happened, act on it”? The first is Change Data Capture. The second is a platform event. This is the question that settles most cases before you look at anything else.
  2. Who owns the payload shape? If you want a stable contract that survives data-model edits, define a platform event. If you are fine with the payload tracking the object and you would rather write no publish code, Change Data Capture is less to build and less to maintain.
  3. Does a downstream system need fields that may not have changed? With Change Data Capture, plan enriched fields and their rules in advance, or you will ship a consumer that works in the demo and starves in production. With a platform event, you simply put the fields in the schema.
  4. Will one serial subscriber keep up? If bursts are real, high-volume platform events and their parallel subscription handle backlogs that change event triggers cannot.

There is a fifth case that settles the choice before you weigh anything: feeding Data 360 with near-real-time changes. The Salesforce connector uses change events under the hood to stream CRM updates into the data model, so if the destination is Data 360, Change Data Capture is already the mechanism and you are configuring it, not choosing it.

Where I land

Change Data Capture is the right default for one job: keeping an external copy of Salesforce data current without writing or maintaining publish code. It is replication, and it is very good at replication.

The moment the requirement becomes “tell system B that something meaningful happened, in a shape B can depend on,” that is a platform event, and trying to make Change Data Capture play that role is how you end up with a subscriber that breaks every time an admin edits a field.

Pick by the message. The event bus does not care which one you publish, but your consumers, and the person who edits that object next quarter, very much do.

Understanding the basics

What is the difference between Change Data Capture and platform events?

Change Data Capture publishes change events automatically whenever a tracked record is created, updated, deleted, or undeleted, with a schema that follows the object. Platform events are messages you define with your own schema and publish deliberately from Apex, Flow, or the API. Change Data Capture is for replicating record changes to another system; platform events are for sending a business or integration message on a contract you control.

Does Change Data Capture replace writing integration code?

For replication, largely yes: you select objects in Setup and the platform emits events with no publish code. But you still write the subscriber, and it has to handle bulk events, idempotency, and the fact that updates carry only changed fields unless you configure enriched fields. For a defined business message, a platform event is usually less trouble overall because its payload is stable.

How long are change events and platform events stored?

Both are retained on the event bus for 72 hours. A subscriber can resume from its last replay Id within that window, but events older than 72 hours are purged. Because the bus is not a durable store, long outages need a separate reconciliation job that reads current state and repairs any drift, which replay alone cannot do.

Why is my Change Data Capture update event missing fields?

An update change event contains only the fields that changed on that update, plus the header. Fields that did not change are absent by design. To always receive specific fields on update and delete events, configure them as enriched fields on a multi-entity channel, up to ten per channel member, and update your client code to tolerate the wider payload.


Designing the eventing layer between Salesforce and the rest of your stack, and want it observable and retry-safe rather than brittle? Talk to us. Choosing the right event, and building consumers that survive a schema change, is exactly the work we do.

Keep reading

All articles