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.

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 fulfilment. 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.

Set Up Postman and Tooling API

Tooling API supports the REST interface, so let’s use a popular REST API tool, Postman, to send REST requests. Set up the Postman desktop app or the web interface with the Salesforce API collection. 

  1. Before you set up Postman, launch your Trailhead Playground so that you’re authenticated in your Playground org.
  2. Follow the installation instructions in the Salesforce APIs for Postman GitHub repository to configure the web UI or the desktop app.
    1. Installing with the Postman Web UI
    2. Installing with the Postman Desktop App
  3. In the Salesforce APIs collection, ensure that the version variable current value is set to at least 51.0. If it is less than 51.0, update it to 51.0 or later.

To learn more about REST support in Salesforce, see Lightning Platform REST Resources in the REST API Developer Guide. For more information about REST resources in Tooling API, see REST Overview in the Tooling API Guide.

Create a Custom Channel

Now that you set up Postman, let’s create a custom channel. 

  1. To send a POST request to PlatformEventChannel, in your forked Salesforce API collection, expand Tooling.
  2. Select POST Post Tooling sObject.
  3. In the new tab that opens for this request, replace the <SOBJECT_API_NAME> placeholder in the URI with PlatformEventChannel. The resulting URI is: {{_endpoint}}/services/data/v{{version}}/tooling/sobjects/PlatformEventChannel
  4. Click Body and ensure that raw and JSON options are selected.
  5. Replace the body with this JSON body.
    {  
      "FullName": "SalesEvents__chn",
      "Metadata": {
        "channelType": "data",
        "label": "Custom Channel for the Sales App"
      }
    }
  6. Click Send.
  7. Verify that the response status is 201 Created.

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

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

This image shows the request and returned response in Postman.

Send a POST request in Postman to create a custom channel.

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