Skip to main content

Create a Custom Channel

Learning Objectives

In this project, you’ll:

  • Create a custom channel with Tooling API.
  • Subscribe to a custom channel and receive an enriched change event.
  • Update existing enriched fields.

Before You Begin

Before you start this module, make sure you complete the Quick Start: Connect Postman to Salesforce project to get set up and fork the Salesforce Platform APIs collection. The work you do here builds on the concepts and work you do in that project. 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.

Also, consider completing the following recommended content to become familiar with platform events and REST API.

What Are Change Data Capture Channels?

Custom channels are useful when there are multiple subscribers and each subscriber receives change events for a different set of objects. Instead of subscribing to the default ChangeEvents channel, your app can create and subscribe to a custom channel that receives only the events for the objects you're interested in. You can create one or more custom channels to group change events on the channel that your app subscribes to. 

Let’s say your company uses an external ERP system for order fulfillment. To ensure that the account records in Salesforce and the ERP system are in sync, you synchronize the account records from Salesforce to the ERP system. Your subscriber app subscribes to a custom channel enabled for sales objects, such as Account, Contact, and Order. Change events for those records are sent on this channel and not other change events. 

In addition to grouping change events, you can use a custom channel with event enrichment to isolate sending enriched fields in change events on a specific channel. You learn more about event enrichment in the next step. 

For more information, see Subscription Channels in the Change Data Capture Developer Guide.

How Do You Create a Custom Channel?

You can create a custom channel with Tooling API or Metadata API using PlatformEventChannel. Each object selected for notifications on a channel is represented by a PlatformEventChannelMember. A channel can have multiple channel members so that it can be enabled for notifications for multiple objects.

In this project, you use Tooling API to create a custom channel. 

Note

If you want to use Metadata API instead, see PlatformEventChannel in the Metadata API Developer Guide.

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 API 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 > Change Data Capture, and click Create channel.
  2. Click Body and ensure that raw and JSON options are selected.
  3. Replace the body with this JSON body.
    {  
      "FullName": "SalesEvents__chn",
      "Metadata": {
        "channelType": "data",
        "label": "Custom Channel for Sales App"
      }
    }
  4. Click Send.
  5. Verify that the response status is 201 Created.

The response returns the ID of the new custom channel, which looks something like this.

{
    "id": "0YL8b000000sXvSGAU",
    "success": true,
    "errors": [],
    "warnings": [],
    "infos": []
}

This image shows the request and returned response in Postman.

The request and response to create a channel in Postman.

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

Resources

Keep learning for
free!
Sign up for an account to continue.
What’s in it for you?
  • Get personalized recommendations for your career goals
  • Practice your skills with hands-on challenges and quizzes
  • Track and share your progress with employers
  • Connect to mentorship and career opportunities