Introduction

Kloudless offers a unified Events API for developers to retrieve real-time notifications via Webhooks for any cloud service that we support. We’ve had to build a unique technical implementation for events from Salesforce based on the different options to efficiently track changes. Salesforce recently updated their platform with two new guides on how to retrieve these events in real-time.

Salesforce offers the following options:

We’ve provided a brief summary of the different options and desired use cases before diving into CometD the core technology used to retrieve events from Salesforce.

Salesforce Events

To differentiate the following events described with each option, Salesforce uses the following terms:

  • Change Data Capture: A Change Event
  • Platform Events: A Platform Event
  • Streaming API: A PushTopic or Generic Event

We’ve copied over the feature comparison chart of the different events from Salesforce.

Change Data Capture

The typical use case for Change Data Capture (CDC) is if your organization wants to keep an external data store of events in sync with Salesforce activity. The end result is that your external data store has a perfect copy of all Salesforce event data that you specify. A primary benefit of using CDC is that the field data can also be encrypted with Shield Platform Encryption. Any change in encrypted field values generate change events whereas this is unsupported in the two other options. The event retention period for CDC events is also 3 days.

Platform Events

The major benefit of Platform Events is user customizability. Unlike Change Data Capture and Streaming API, the developer has to build and configure the “Platform Event” that Salesforce will return. In addition, Platform Events has a deeper integration with the Apex platform by being able to publish and subscribe to events via Apex.  Therefore, I would recommend using Platform Events if the Apex platform is crucial to your organization’s use case, and you have the developer resources to handle the customization.

Streaming API

The Streaming API is Salesforce’s original mechanism to retrieve events and offers the ability to retrieve both PushTopic and Generic events.  A PushTopic event is configured by creating a SOQL query that will return all events that match that configuration. A Generic event is configured to when wanting to send or receive custom notifications that are not tied to Salesforce data changes.  Since the primary use cases of CDC and Platform Events revolve around Salesforce data changes, we will mostly be considering PushTopic events. PushTopic events strike a balance between CDC and Platform events since you can customize the type of event data via PushTopics as well as use the default objects without having to create each individual event like in Platform Events.

CometD | Bayeaux Protocol

CometD uses a simple publish and subscribe process to receive messages across channels.  Salesforce has the following channels to establish a connection:

  • /meta/handshake
  • /meta/connect
  • /meta/disconnect
  • /meta/subscribe
  • /meta/unsubscribe

Once a connection is established, the client can send messages to receive events based on a specific replay ID.  Since Salesforce allows all types of events to be returned when using CometD, we’ve provided examples of messages returned for each event type.

Generic Event Message

PushTopic Event Message

Platform Event Message

Change Data Capture Event Message

Kloudless Events

Although Salesforce suggests using the open source EMP Connector, Kloudless decided to implement the Bayeaux Protocol using Python as part of its native stack. Kloudless abstracts away the complexity of connecting to the Streaming API by providing a REST interface to retrieve events. Kloudless combines the best of all three options by being the external data store of events with the customizability. We’ve shown a curl request below that creates a PushTopic, which Kloudless subscribes to for events.

Retrieve Kloudless events for Salesforce by using our Events API. Here is a sample request below:

With Kloudless Enterprise, our customers have sub-minute notifications of activity for a number of cloud services including Salesforce.  Kloudless is the ideal solution for your application if you do not want to implement your own pub/sub client, or if you want to have a far simpler integration with Salesforce.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.