Newer Version Available
Create a Custom Channel and Add Platform Events with Tooling API
In this example, you create a channel for orders named Order_Channel__chn, and you add
two platform events as members: Order_NorthAmer__e and Order_EMEA__e.
| User Permissions Needed | |
|---|---|
| To create or update PlatformEventChannel and PlatformEventChannelMember objects: | Customize Application |
| To use REST API: | API Enabled |
You can use your preferred REST API tool to perform these steps. We recommend using Postman with the Salesforce API Collection, which contains handy templates for Salesforce API calls. To set up Postman, see Salesforce APIs for Postman.
-
Create the channel using PlatformEventChannel, and set the channelType field to event. Send a POST request
to this URI.
1/services/data/v55.0/tooling/sobjects/PlatformEventChannel -
Use this request body.
1{ 2 "FullName": "Order_Channel__chn", 3 "Metadata": { 4 "channelType": "event", 5 "label": "Custom Channel for Orders" 6 } 7}You receive a response similar to this response.1{ 2 "id": "0YLRM0000004CEI4A2", 3 "success": true, 4 "errors": [], 5 "warnings": [], 6 "infos": [] 7} -
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/v55.0/tooling/sobjects/PlatformEventChannelMember -
Use this request body.
1{ 2 "FullName": "Order_Channel_chn_Order_NorthAmer_e", 3 "Metadata": { 4 "eventChannel": "Order_Channel__chn", 5 "selectedEntity": "Order_NorthAmer__e" 6 } 7}You receive a response similar to this response.1{ 2 "id": "0v8RM0000000N6uYAE", 3 "success": true, 4 "errors": [], 5 "warnings": [], 6 "infos": [] 7} -
Add the second channel member that specifies the platform event, Order_EMEA__e. Send a POST
request to this URI.
1/services/data/v55.0/tooling/sobjects/PlatformEventChannelMember -
Use this request body.
1{ 2 "FullName": "Order_Channel_chn_Order_EMEA_e", 3 "Metadata": { 4 "eventChannel": "Order_Channel__chn", 5 "selectedEntity": "Order_EMEA__e" 6 } 7}You receive a response similar to this response.1{ 2 "id": "0v8RM0000004VPJYA2", 3 "success": true, 4 "errors": [], 5 "warnings": [], 6 "infos": [] 7}