Enrich CDC and Event Filter

Change Data Capture (CDC) are published by the platform and there is no specific limits around how many CDC would get published. Also, because of the same reason that platform is publishing these events what information would get passed is also pre-set and as a developer we did not any control over it.

With new integration patterns following the event driven architecture there are quite of use cases where Salesforce CDC were not of help because of two primary reasons
1) Lack of ability to add information being passed in CDC
2) Processing overheads: Solution had to process lots of events which were not intended for it.

Enrich fields and event filtering has now been introduced to rescue. On top of it also allows you to subscribe to single channel and listen to CDC from multiple objects or custom platform events.

Enrichment is available only for CDC. 
Filtering is available for CDC as well as custom platform events.

Important thing to note is event filtering or CDC enrichment is supported via Platform Event Channels only.


What is Platform Event Chanel?

Channel is a stream of events in the Salesforce event bus which can have either multiple types of platform events or multiple change data capture events (not both in single channel)

Platform Event Channel is essentially an object in Salesforce and records of this object can be created via metadata or tooling APIs only.


How Platform Event Channel can be created and subscribed?

There couple of types of channels which platform provides and on top it platform allows to create custom channels as well.

Platform provided channels:

1) Standard Channel:

This channel can be used to receive CDC from all entities for which the CDC is enabled
Name of channel for subscription: /data/ChangeEvents

2) Single Entity Standard Channel:

This channel can be used to receive CDC of specific standard or custom object
Name of the channel for standard object CDC for subscription: /data/<standard object name>ChangeEvent

E.g. for Account object the channel name would be /data/AccountChangeEvent

Name of the channel for custom object CDC for subscription: /data/<Custom_Object_Name>__ChangeEvent

E.g. for Car__c custom object the channel name would be /data/Car__ChangeEvent


Custom Channel:

Such channels can be used to receive CDC from limited objects though CDC is enabled for multiple objects or to receive multiple platform events.

It can be created using Tooling API or Metadata API


Name of the custom channel for subscription: /data/<Channel_Name>__chn

Subscribing to channels is going to be same as subscribing to platform event. Only change is instead of platform event name, channel name should be used. However, channel name is case-sensitive and triggers or flows can not be used to subscribe to channel.


How to add CDC or custom platform events in the channel and enrich CDC?

Similar Platform Event Chanel there is another object called Platform Event Channel Member.
By creating the record of this object a member gets linked to Platform Event Channel.
Also for adding the fields in CDC it accepts array where multiple fields can be added.



Thanks for your time to go through the post, hope it helps!

Popular posts from this blog

Create File versions from Apex

Run as different user in Apex

Creating JKS certificate for JWT Bearer flow in Salesforce