Add a Filter with Tooling API
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 Platform APIs collection, which contains handy templates for Salesforce API calls. To set up Postman, see Quick Start: Connect Postman to Salesforce in Trailhead.
-
To create a channel, send a POST request to this URI.
/services/data/v63.0/tooling/sobjects/PlatformEventChannel
If you're using Postman, expand
, and click Create channel. -
Use this example request body. To have this channel accept platform events, event is specified for channelType.
{ "FullName": "MyChannel__chn", "Metadata": { "channelType": "event", "label": "Custom Channel for Platform Events" } }
You receive a response similar to this example response.{ "id" : "0YLRM000000004X4AQ", "success" : true, "errors" : [ ], "warnings" : [ ], "infos" : [ ] }
-
Add a channel member that specifies the custom platform event and filter expression. This
example references the custom platform event, Order_Event__e. Send a POST request to this
URI.
/services/data/v63.0/tooling/sobjects/PlatformEventChannelMember
If you're using Postman, expand
, and click Create channel member. -
Use this example request body.
{ "FullName": "MyChannel_chn_Order_Event_e", "Metadata": { "eventChannel": "MyChannel__chn", "filterExpression": "(City__c LIKE 'S%' OR City__c='New York') AND Amount__c>10.50", "selectedEntity": "Order_Event__e" } }
You receive a response similar to this example response.{ "id" : "0v8RM0000000MnNYAU", "success" : true, "errors" : [ ], "warnings" : [ ], "infos" : [ ] }
To update a filter expression, perform a PATCH request to /services/data/v63.0/tooling/sobjects/PlatformEventChannelMember/<ChannelMemberID>, and pass in the entire request body with the new filter expression. You can update only the filterExpression field of a channel member. All other fields aren’t updateable.
{
"FullName": "MyChannel_chn_Order_Event_e",
"Metadata": {
"eventChannel": "MyChannel__chn",
"filterExpression": "(ns__City__c LIKE 'S%' OR ns__City__c='New York') AND ns__Amount__c>10.50",
"selectedEntity": "ns__Order_Event__e"
}
}