What is Change Data Capture?

With so many different flavors of streaming events, how do you choose the right one for your use case? In this post, we’ll talk about our newest streaming event called Change Data Capture and compare it to the other events offered on the Lightning Platform.

What is a Change Data Capture event?

A Change Data Capture event, or change event, is a notification that Salesforce sends when a change to a Salesforce record occurs as part of a create, update, delete, or undelete operation. The notification includes all new and changed fields, and header fields that contain information about the change. For example, header fields indicate the type of change that triggered the event and the origin of the change. Change events support all custom objects and a subset of standard objects.

Event payload example

This change event message is sent when an account record is created with a Name and Description field.

When to use Change Data Capture

Receive notifications of Salesforce record changes, including create, update, delete, and undelete operations.

Capture field changes for all records.

Get broad access to all data regardless of sharing rules.

Get information about the change in the event header, such as the origin of the change, which allows ignoring changes that your client generates.

Perform data updates using transaction boundaries.

Use a versioned event schema.

Subscribe to mass changes in a scalable way.

Get access to retained events for up to three days.

Example: Data replication to an external data store

Get Cloudy Consulting has a project for a client. This client wants an integration that synchronizes Salesforce record data changes with their HR system, which is external to Salesforce. Some of the client’s HR data is created and modified in Salesforce as Employee__c custom object records. The client wants the employee data in the external HR system to be in sync with Salesforce.

The integration app has the following requirements:

Every new or changed Employee__c record is replicated in the HR data store.

All Employee__c records are replicated along with their fields.

The replication is transaction-based. If multiple updates are in a single transaction, the integration app sends these updates as part of one transaction as well.

If the data replication process fails, it’s possible to resume the replication from past event notifications that are stored for up to three days.

After reviewing the different event streaming options in Salesforce, Robert, a software engineer at Get Cloudy Consulting, decides that Change Data Capture is the answer for the integration app. By subscribing to the channel for the Employee__c custom object, the app receives notifications for every change with all modified fields. The app can inspect the transactionKey and isTransactionEnd header fields in the notification to figure out if the change can be committed right away, or if the change should be combined with other changes and committed when isTransactionEnd = true. Because change events are stored for up to three days, the app can retrieve missed notifications.

Streaming event features

The following table compares the features offered by each streaming event, including Change Data Capture events.

With all this great information on our newest kind of event, we hope to see some amazing new use cases and solutions. Want to show us what you’ve created? Share on Twitter and tag @SalesforceDevs.