What is Change Data Capture?

This was originally published on link to post

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.

Important: Change Data Capture is available as a developer preview in Developer Edition orgs. Change Data Capture isn’t generally available unless or until Salesforce announces its general availability in documentation or in press releases or public statements. All commands, parameters, and other features are subject to change or deprecation at any time, with or without notice. Don’t implement functionality developed with these commands or tools. In addition to the developer preview, Change Data Capture continues to be offered through a pilot program to select customers. To be nominated to participate in the pilot program, contact Salesforce. You can provide feedback and suggestions for Change Data Capture in this Trailblazer community group.

What is a Change Data Capture (CDC) event?

A CDC 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.

{
     "data": {
         "schema": "IeRuaY6cbI_HsV8Rv1Mc5g", 
         "payload": {
             "ChangeEventHeader": {
                 "entityName": "Account", 
                 "recordIds": [
                    "<record_ID>"
                  ], 
                  "changeType": "CREATE", 
                  "changeOrigin": "com.salesforce.core", 
                  "transactionKey": "001b7375-0086-250e-e6ca-b99bc3a8b69f", 
                  "sequenceNumber": 1, 
                  "isTransactionEnd": true, 
                  "commitTimestamp": 1501010206653, 
                  "commitNumber": 92847272780, 
                  "commitUser": "<User_ID>"
             }, 
             "Name": "Acme", 
             "Description": "Worldwide leader in gadgets of the future.", 
             "OwnerId": "<Owner_ID>", 
             "CreatedDate": "2018-03-11T19:16:44Z", 
             "CreatedById": "<User_ID>", 
             "LastModifiedDate": "2018-03-11T19:16:44Z", 
             "LastModifiedById": "<User_ID>"
  }, 
  "event": {
      "replayId": 6
  }
 }, 
 "channel": "/data/ChangeEvents"
}

 

When to use Change Data Capture

Use change events to:

  • 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 CDC 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.

Resources

Change Data Capture

More on streaming events

About the author

Katia Hage is a technical writer on the platform content experience team at Salesforce.

Continue Reading this post here  Salesforce

Katia Hage

Leave a Reply

Your email address will not be published. Required fields are marked *