Skip to main content

Create a Custom Channel for Order Events

Learning Objectives

In this project, you’ll:

  • Create a custom channel using Tooling API.
  • Define the Order_Event__e platform event.
  • Create a channel member that specifies the Order Event and filter expression using Tooling API.
  • Install the Streaming Monitor AppExchange app.
  • Subscribe to the channel using the Streaming Monitor app.
  • Publish several order events using REST API in Postman.
  • Verify the events received in the Streaming Monitor app.

Before You Begin

Before you start this project, we recommend that you become familiar with platform events and REST API. To learn about those technologies, check out these resources.

While you can use any REST API tool or HTTP client app to make REST API calls, in this project we show you the steps to make REST API calls using Postman. If you haven't used Postman yet, visit the Quick Start: Connect Postman to Salesforce project to get set up and fork the Salesforce Platform APIs collection.

Filter Event Streams with Custom Channels

In this project, you filter an event stream to receive only the event messages you’re interested in. With fewer events delivered to your subscriber app, you optimize event processing and make more efficient use of the event delivery allocation. Your subscriber app can process a smaller volume of events faster and is less likely to hit the event delivery limit.

A funnel representing a filtered event stream.

Let’s take a closer look at a scenario for this project.

You have subscriber apps that process 30,000 order events per geographical location per day. And you don’t want all apps to receive all the events. You want each app to receive only the events it will process.  

For example, of the 30,000 order events per day, only 5,000 are for the city of San Francisco. For this project, you subscribe one of the apps to a custom channel that filters the stream for the city of San Francisco, so that the app receives and processes only those 5,000 events. By doing that, the event delivery usage that’s counted against your event delivery allocation will be 5,000 events for that app.  

Stream filtering is used with event channels that Pub/Sub API and Streaming API (CometD) clients subscribe to. Stream filtering is supported for custom platform events and change data capture events. An event channel is a stream of event messages corresponding to one or more platform events defined in your Salesforce org, or one or more predefined change data capture events. You can add a filter expression in a channel member. The filter expression specifies the event fields and values you want to filter the event stream with. 

Note

This project focuses on platform events, but the same concepts apply to change data capture events also. To learn more, check out Filter Your Stream of Change Events with Channels in the Change Data Capture Developer Guide.

Create a Custom Channel

Before you configure stream filtering, create a custom platform event channel. You can create a custom channel with Tooling API or Metadata API using PlatformEventChannel. In this project, you use Tooling API to create a custom channel. Let's get started.

Launch Your Trailhead Playground

You complete this hands-on project in your own personal Trailhead Playground. Make sure you are logged in to Trailhead, then get your Trailhead Playground by clicking Launch at the bottom of this page. Your playground opens in a new browser tab or window. After you complete the steps in your playground, click Verify step at the bottom of the page.

Connect Your Trailhead Playground Org with Postman

  1. Log in to your Trailhead Playground org.
  2. After you set up Postman by completing the Quick Start: Connect Postman to Salesforce project, open the Postman app, select a Workspace, and navigate to your fork of the Salesforce Platform APIs collection.
  3. On the Authorization tab, scroll to the bottom and click Get New Access Token.
  4. Click Allow.
  5. In the Manage Access Tokens dialog, copy the instance URL to your clipboard.
  6. Click Use Token.
  7. On the Variables tab, in the _endpoint row, in the CURRENT VALUE column, paste the instance URL that you just copied, then click Save. You may need to close the documentation pane to see the Save button.
  8. Test that your connection is working.
  9. In Collections, select your fork of the Salesforce Platform APIs collection.
  10. Select REST to expand the REST APIs.
  11. Select GET Limits, then click Send.
  12. In the response window, the Status field should show as Status: 200 OK. If it does not, repeat the steps to get a new token.

Make a Tooling API Call to Create a Custom Channel

  1. In your fork of the Salesforce Platform APIs collection, expand Event Platform > Custom Channels > Platform Event, and click Create channel.
  2. Click Body and replace the body with this JSON body.
    {
      "FullName": "Order_Filtered_Channel__chn",
      "Metadata": {
        "channelType": "event",
        "label": "Order Filtered Channel"
      }
    }
  3. Click Send.
  4. Verify that the response status is 201 Created.
  5. The response contains the ID of the new custom channel, which looks something like this.
    {
        "id": "0YL8b000000CaTNGA0",
        "success": true,
        "errors": [],
        "warnings": [],
        "infos": []
    }

This image shows the request and returned response in Postman.

The Postman app containing the result of channel creation.

Note

In this step, you created a channel for platform events with channelType of event. This channelType value means that the channel can reference custom platform events through its members. If you want the channel to reference change data capture events, such as AccountChangeEvent, through its members, set the channelType to data instead. 

Congratulations! You created a custom channel! You use this channel in the next step to add a channel member and configure stream filtering. 

Resources

Share your Trailhead feedback over on Salesforce Help.

We'd love to hear about your experience with Trailhead - you can now access the new feedback form anytime from the Salesforce Help site.

Learn More Continue to Share Feedback