Newer Version Available
Group Platform Events into One Stream with a Custom Channel
Types of Events Supported
Custom channels are supported for high-volume custom platform events that you define. They aren’t supported for legacy standard-volume custom platform events or standard platform events, such as real-time event monitoring events.
PlatformEventChannel and PlatformEventChannelMember Objects in the API
Create a custom channel, and specify the platform events it contains in Tooling API and Metadata API.
PlatformEventChannel represents a custom channel. The ChannelType field indicates which members the custom channel can contain. A ChannelType value of event means that the channel can contain platform events via its channel members.
A custom channel can contain events for only one event product. You can’t mix events from different event products in one channel. For example, you can’t add platform events and change data capture events to the same channel.
PlatformEventChannelMember represents a member of a channel. It contains a custom platform event in the SelectedEntity field and is associated with the channel via the EventChannel field.
Example Diagram
This diagram shows the object relationships and definitions of the custom channel Order_Channel__chn and its members. The channel is set up to receive order events for North America, EMEA, and the APAC regions. A custom event is defined for each region: Order_NorthAmer__e, Order_EMEA__e, Order_APAC__e. Each of these platform events is added to the channel via PlatformEventChannelMember objects. An order management app can subscribe to the custom channel, Order_Channel__chn, and receive messages of the three platform events.
Subscribing to a Custom Channel
When you subscribe to the custom channel with CometD, provide the channel name in the format /event/ChannelName__chn, such as /event/Order_Channel__chn. Your subscriber receives event messages of all events that are part of the channel. In a CometD client, each event message contains the EventApiName field, which contains the type of the event. For example, this event message has an EventApiName of Order_EMEA__e, which means that it’s an Order_EMEA__e event.
1{
2 "schema": "e8jMOnID4xDThlaPBMx5gg",
3 "payload": {
4 "City__c": "London",
5 "CreatedById": "005RM000002Qu16YAC",
6 "Amount__c": 20,
7 "CreatedDate": "2022-03-29T13:45:19.230Z",
8 "Order_Number__c": "2"
9 },
10 "event": {
11 "EventApiName": "Order_EMEA__e",
12 "EventUuid": "218544ad-0472-4315-970f-8825a2802de6",
13 "replayId": 10306
14 }
15}The EventApiName field is available in event messages received in CometD clients that use a Streaming API endpoint with API version 55.0 and later. It isn't available in event messages received in other subscribers, such as Apex triggers, flows, and Pub/Sub API. It isn't included in change data capture events and events that don't support custom channels. Also, the EventApiName field isn’t part of the event schema that the REST eventSchema resource or the describe call returns. To determine the type of the event received with Pub/Sub API, retrieve the event schema with the GetSchema RPC method using the schema ID contained in the received event. The schema name is in the schema_json field in the response and identifies the event type. For more information, see GetSchema RPC Method in the Pub/Sub API Developer Guide.
Custom Channel Allocations
You can create up to 100 custom channels regardless of your Salesforce org edition. For Performance, Unlimited, and Enterprise Editions, you can add up to 50 distinct platform events as part of channel members to a custom channel. For Developer Edition and Professional Edition with the API add-on, this allocation is 5 distinct platform events. If the same platform event is a member of multiple channels, it’s counted once toward the allocation. These allocations are separate from change data capture channel allocations.