Create a Custom Channel and Add Real-Time Event Monitoring Events with Tooling API

Create a channel for Real-Time Event Monitoring events named Event_Monitoring_Channel__chn by using the eventType field in PlatformEventChannel. Also, add two Real-Time Event Monitoring events as members: ApiAnomalyEvent and FileEvent.

Before You Begin 

User Permissions Needed
To create or update PlatformEventChannel and PlatformEventChannelMember objects:Customize Application
To use REST API:API Enabled
To use Real-Time Event Monitoring events:Salesforce Shield or Event Monitoring add-on subscription and the View Real-Time Event Monitoring Data user permission.

You can use your preferred REST API tool to perform these steps. We recommend using Postman with the Salesforce Platform APIs collection, which contains handy templates for Salesforce API calls. To set up Postman, see Quick Start: Connect Postman to Salesforce in Trailhead.

  1. Create the channel using PlatformEventChannel, set the channelType field to event and the eventType field to monitoring. Send a POST request to this URI.

    1/services/data/v68.0/tooling/sobjects/PlatformEventChannel

    If you’re using Postman, expand Event Platform | Custom Channels | Platform Event, and then click Create channel.

  2. Use this request body.

    1{
    2  "FullName": "Event_Monitoring_Channel__chn",
    3  "Metadata": {
    4    "channelType": "event",
    5    "eventType": "monitoring",
    6    "label": "Custom Channel for Real-Time Event Monitoring events"
    7  }
    8}

    You receive a response similar to this response.

    1{
    2  "id": "0YLZM000000CaR74AK",
    3  "success": true,
    4  "errors": [],
    5  "warnings": [],
    6  "infos": []
    7}
  3. Add the Order_NorthAmer__e platform event to the channel using PlatformEventChannelMember. The channel member references the channel it’s part of (Order_Channel__chn) through the eventChannel field. Specify the platform event in the selectedEntity field. Send a POST request to this URI.

    1/services/data/v68.0/tooling/sobjects/PlatformEventChannelMember

    If you’re using Postman, expand Event Platform | Custom Channels | Platform Event, and then click Create channel member.

  4. Use this request body.

    1{
    2 "FullName": "Event_Monitoring_Channel_chn_ApiAnomalyEvent",
    3 "Metadata": {
    4  "eventChannel": "Event_Monitoring_Channel__chn",
    5  "selectedEntity": "ApiAnomalyEvent"
    6 }
    7}

    You receive a response similar to this response.

    1{
    2  "id": "0v8ZM000000CaeZYAS",
    3  "success": true,
    4  "errors": [],
    5  "warnings": [],
    6  "infos": []
    7}
  5. Add the second channel member that specifies the platform event, Order_EMEA__e. Send a POST request to this URI.

    1/services/data/v68.0/tooling/sobjects/PlatformEventChannelMember

    If you’re using Postman, expand Event Platform | Custom Channels | Platform Event, and click Create channel member.

  6. Use this request body.

    1{
    2 "FullName": "Event_Monitoring_Channel_chn_FileEvent",
    3 "Metadata": {
    4  "eventChannel": "Event_Monitoring_Channel__chn",
    5  "selectedEntity": "FileEvent"
    6 }
    7}

    You receive a response similar to this response.

    1{
    2  "id": "0v8ZM0000008OPVYA2",
    3  "success": true,
    4  "errors": [],
    5  "warnings": [],
    6  "infos": []
    7}

Next Steps 

Before you subscribe to the Event_Monitoring_Channel__chn channel, enable Real-Time Event Monitoring and streaming for the specific events. See Enable Access to Real-Time Event Monitoring and Manage Real-Time Event Monitoring Events in Salesforce Help.

To subscribe to the channel, see Subscribe to the Channel and use /event/Event_Monitoring_Channel__chn for the TOPIC parameter. After you start the subscription, perform some actions in the Salesforce org to cause some events to be generated. For example, to receive FileEvent events on the channel, download a document.

See Also