← Back to Platform & Technical
PLAT-011 Platform & Technical 20 min read For: Architects

Change Data Capture: Event-Driven Integration Done Right

How CDC works at the infrastructure level, what information is in each event, how to subscribe from Apex triggers and external systems, the 72-hour replay window, and how CDC compares to Outbound Messaging and polling-based integration patterns.

VS

Vishal Sharma

Salesforce Architecture Specialist · Updated May 2026

What You'll Learn

How CDC works at the infrastructure level, what information is in each event, how to subscribe from Apex triggers and external systems, the 72-hour replay window, and how CDC compares to Outbound Messaging and polling-based integration patterns.

The Problem CDC Solves

Traditional Salesforce integration relied on polling — an external system periodically calling the Salesforce API to ask "what changed since I last checked?" Polling has three fundamental problems: latency (changes are only detected on the next poll cycle), API cost (every poll consumes API calls even when nothing has changed), and complexity (the subscriber must track its own cursor and handle missed updates).

Change Data Capture (CDC) inverts this model. Salesforce publishes an event to a channel whenever a record is created, updated, deleted, or undeleted. External systems subscribe to the channel and receive events in near real time. No polling, no cursor management, no wasted API calls.

Insight CDC is Salesforce's implementation of the database change log pattern, similar to Debezium on PostgreSQL or AWS DMS on RDS. The key insight is that the source of truth (Salesforce) pushes changes to consumers, rather than consumers pulling. This eliminates polling latency and reduces API consumption.

Event Structure and Change Types

A CDC event contains: the record ID, the operation type (Create, Update, Delete, Undelete), a transaction key, a sequence number, the changed field values (for updates — only the changed fields, not the full record), and the ID of the user who made the change.

The five operation types:

  • CREATE: New record created. Event contains all selected field values.
  • UPDATE: Record modified. Event contains only the fields that changed — this is a delta, not a full snapshot.
  • DELETE: Record soft-deleted (moved to Recycle Bin). No field values included.
  • UNDELETE: Record restored from Recycle Bin. Event contains selected field values.
  • GAP_*: Special event types indicating that events were not captured for a period (usually due to bulk API operations that bypass triggers).
// CDC event payload example (Account UPDATE)
{
  "schema": "TIOb-jG_qRb2ucSBIdByMA",
  "payload": {
    "ChangeEventHeader": {
      "entityName": "Account",
      "recordIds": ["0012x000004C9PuAAK"],
      "changeType": "UPDATE",
      "changedFields": ["Name", "Phone", "LastModifiedDate"],
      "changeOrigin": "com/salesforce/api/soap/56.0;client=SfdcInternalAPI/",
      "transactionKey": "000ae764-ab05-1234-88b3-fe1234567890",
      "sequenceNumber": 3,
      "commitTimestamp": 1716288000000,
      "commitUser": "0055g000003FABCAA4"
    },
    "Name": "Acme Corp Updated",
    "Phone": "+1 415 555 0100"
  }
}
Key Point For UPDATE events, only the changed fields are included in the payload. A subscriber that needs the full current state must call back to Salesforce with a SOQL query using the recordId from the event. This is by design — it reduces payload size and avoids transmitting sensitive fields that did not change.

Enabling CDC and the 72-Hour Replay Window

CDC is enabled per object from Setup > Integrations > Change Data Capture. Standard objects and custom objects are supported. Once enabled, Salesforce begins publishing events to the object's channel (e.g. /data/AccountChangeEvent).

Events are retained in the Salesforce event bus for 72 hours. Subscribers that go offline for less than 72 hours can replay missed events by providing a replay ID when reconnecting. This is the most important reliability feature of CDC — it means brief subscriber downtime does not cause data loss.

// Apex trigger subscribing to CDC events
trigger AccountCDCTrigger on AccountChangeEvent (after insert) {
  for (AccountChangeEvent event : Trigger.new) {
    EventBus.ChangeEventHeader header = event.ChangeEventHeader;

    if (header.changeType == 'UPDATE') {
      // Process updated accounts
      List<String> recordIds = header.recordIds;
      Set<String> changedFields = new Set<String>(header.changedFields);

      if (changedFields.contains('Name') || changedFields.contains('Phone')) {
        // Enqueue downstream sync
        System.enqueueJob(new AccountSyncJob(recordIds));
      }
    }
  }
}

// External system subscribing via CometD (JavaScript)
const client = new CometD();
client.subscribe('/data/AccountChangeEvent', (message) => {
  const { changeType, recordIds, changedFields } =
    message.data.payload.ChangeEventHeader;
  console.log(`${changeType} on ${recordIds[0]}: ${changedFields}`);
  if (changeType === 'UPDATE') processAccountUpdate(message.data.payload);
});

CDC vs Outbound Messaging vs Platform Events

Salesforce has three event-based integration mechanisms with different trade-offs:

  • CDC: Automatic change capture on record DML. No trigger code needed. Configured declaratively. Includes change type, changed fields, and user. Best for replication to external systems.
  • Outbound Messaging (OM): SOAP-based, workflow-triggered. Fires on record changes that match a workflow rule. Delivers the full record (not just changed fields) to a configured SOAP endpoint. Does not support replay. Legacy mechanism — prefer CDC for new integrations.
  • Platform Events (PE): Custom event schema defined by the developer. Published programmatically (Apex, API, Flow). Not record-change-based — used for application-level events (order.placed, payment.processed). Best for application events that are not direct record changes.
Tip Use CDC when you need to replicate Salesforce record changes to an external data store (data warehouse, ERP, marketing platform). Use Platform Events when you need to trigger business processes based on application-level events. Use Outbound Messaging only if you are maintaining a legacy SOAP-based integration and cannot migrate.

GAP Events and Bulk API Blind Spots

CDC has one significant blind spot: Bulk API 1.0 operations do not generate CDC events. When a data loader or ETL tool uses the Bulk API to insert or update 100,000 records, no CDC events fire. Instead, Salesforce may publish a GAP_CREATE or GAP_UPDATE event to indicate that changes occurred but were not captured.

Subscribers must handle GAP events by triggering a full reconciliation query against Salesforce for the affected object. This is rare in production but happens during initial data loads and data migrations. Design your subscriber to detect GAP events and escalate to a reconciliation workflow rather than silently skipping them.

Warning Teams that use Bulk API for ongoing data loads (nightly ETL from ERP to Salesforce) cannot rely on CDC to replicate those changes back out. The CDC subscriber will receive GAP events for those bulk operations. Design your integration architecture with this blind spot in mind — CDC works best when changes enter Salesforce through the UI or standard REST/SOAP API.

Key Takeaways

  • CDC eliminates polling — Salesforce pushes events on every record create, update, delete, and undelete.
  • UPDATE events contain only changed fields (delta), not the full record. Use the recordId to query the full record if needed.
  • Events are retained for 72 hours, enabling missed-event replay on subscriber reconnection.
  • Bulk API 1.0 operations bypass CDC — subscribers receive GAP events and must trigger reconciliation queries.
  • CDC is best for record replication to external systems. Platform Events are best for application-level business event choreography.
  • Subscribe from Apex triggers (server-side) or via CometD/Pub-Sub API (external system).

Check Your Understanding

1. What does a CDC UPDATE event payload contain about the changed record?

A. The full record snapshot including all selected fields
B. Only the fields that changed, plus the record ID and change metadata
C. Only the record ID — you must query Salesforce separately for all field values

2. A subscriber goes offline for 50 hours and misses events. What happens when it reconnects?

A. The events are permanently lost — CDC has no retry mechanism
B. The subscriber can replay the missed events using the replay ID, as events are retained for 72 hours
C. Salesforce re-triggers all missed events automatically without any subscriber configuration

3. Which scenario causes CDC to publish GAP events rather than normal change events?

A. A Flow updating 200 records in a loop
B. A Bulk API 1.0 data load updating 50,000 records
C. A user updating 10 records through the Lightning UI

Discussion & Feedback