Add the Order Event and the Filter Expression to a Channel Member
Define the Order Platform Event
Before you can add a channel member, define the platform event that the channel member references.
- From Setup, in the Quick Find box, enter
Platform Events
, and then select Platform Events.
- Click New Platform Event.
- Provide these values.
- Label:
Order Event
- Plural Label:
Order Events
- Select Starts with a vowel sound, if available.
- Click Save.
- Create three fields. In Custom Fields & Relationships, click New for each field, and follow the wizard.
Field Type |
Field Label |
Field Length |
---|---|---|
Text |
Order Number |
10 |
Text |
City |
50 |
Number |
Amount |
16 Decimal Places: 2 |
Filter Expression in a Channel Member
To filter your event stream, add a filter expression to a member of a channel, which is represented by PlatformEventChannelMember in Tooling API and Metadata API. The filter expression is for each event entity. The channel member specifies the event entity that is streamed on that channel and also the filter expression that is used to filter the stream of events. A channel can contain multiple members and each member references a distinct event entity. In this project, you add only one channel member for simplicity.
The filter expression specifies the event fields and values you want to filter the event stream with. It is based on SOQL and supports a subset of SOQL operators and field types. The filter expression can contain one or more field expressions, joined by a logical operator. In this example, you use this filter expression:
City__c='San Francisco' AND Amount__c<1000
The filtered channel delivers only the event messages that contain the City field value of San Francisco and an Amount field value less than 1,000.
For more information about what the filter expression can contain, see Platform Event Filters in the Platform Events Developer Guide.
Make a Tooling API Call to Create a Channel Member
- In your fork of the Salesforce Platform APIs collection, expand Event Platform > Custom Channels > Platform Event, and click Create channel member.
- Click Body and replace the body with this JSON body.
{ "FullName": "Order_Filtered_Channel_chn_Order_Event_e", "Metadata": { "eventChannel": "Order_Filtered_Channel__chn", "filterExpression": "City__c='San Francisco' AND Amount__c<1000", "selectedEntity": "Order_Event__e" } }
- Click Send.
- Verify that the response status is 201 Created.
- The response contains the ID of the new custom channel member, which looks something like this.
{ "id": "0v88b00000000m1AAA", "success": true, "errors": [], "warnings": [], "infos": [] }
Congratulations! You added a filter to a custom channel! Next, you subscribe to the filtered channel and receive a filtered event stream.
Resources
- Platform Events Developer Guide: Filter Your Stream of Platform Events with Custom Channels
- Tooling API Developer Guide: PlatformEventChannel
- Tooling API Developer Guide: PlatformEventChannelMember