Newer Version Available

This content describes an older version of this product. View Latest

Subscribe to the Channel

After creating the custom channel and its members, subscribe to the channel using a CometD client, and receive event messages. Only CometD clients support custom channels. Other subscribers, such as Apex triggers, flows, and processes, don’t support custom channels.
  1. To set up EMP Connector, follow the steps in Example: Subscribe to Events Using a CometD Client (EMP Connector). For the channel argument, provide the custom channel that you created: /event/Order_Channel__chn. The channel name is format /event/ChannelName__chn.

    To receive the EventApiName field, ensure that the client is subscribed with the Streaming API endpoint of API version 55.0 or later. See API Version in the Streaming API Endpoint in the EMP Connector GitHub repo.

    Note

  2. Now that you’re subscribed to the custom channel, publish event messages of both events, Order_NorthAmer__e and Order_EMEA__e, in the Developer Console using Apex.
    1. In Salesforce Classic, select your name | Developer Console.
    2. In Lightning Experience, click the quick access menu, and select Developer Console.
    3. Select Debug | Open Execute Anonymous Window.
    4. In the new window, replace the contents with this Apex code snippet, and click Execute.

      Notice that the eventList variable is declared with the SObject type and not the event type (for example, Order_NorthAmer__e). Using SObject enables this list variable to hold any event type, for example, Order_NorthAmer__e and Order_EMEA__e.

      Note

    Because Order_Channel__chn includes both the Order_NorthAmer__e and Order_EMEA__e event types, you receive the event messages of both events. This example shows the two received event messages after subscribing to the filtered channel, /event/Order_Channel__chn.