1

We are starting to see a high utilization of daily delivered platform events.

We are looking for ways to lower the daily delivered platform event limit. One of the solutions will look into using a criteria filter on the subscribe platform events. We have not seen much documentation on what adding a criteria filter to the subscription can do.

I looked here and I could not find anything about the use of criteria filter: https://developer.salesforce.com/docs/atlas.en-us.platform_events.meta/platform_events/platform_events_subscribe.htm

Can you provide us with documentation on adding a criteria filter?

Here is the example that we are using:

// Define the subscription criteria
const platformEventName = 'My_Platform_Event__e';
const channelName = '/event/' + platformEventName;
const criteria = {
recordTypeId: {
$in: ['012xx0000000000AAA', '012xx0000000000BBB']
}
};

// Subscribe to the platform event with the criteria
subscribe(channelName, -1, (event) => {
// Handle the received event
console.log('Received event: ' + JSON.stringify(event));
}, criteria)
.then(response => {
console.log('Subscribed to channel ' + channelName);
})
4

1 Answer 1

1

This Add a Filter with the Tooling API page goes through the steps. There's no UX to do this.

  1. Add a PlatformEventChannel

     /services/data/v59.0/tooling/sobjects/PlatformEventChannel
    
     {
      "FullName": "MyChannel__chn",
      "Metadata": {
      "channelType": "event",
      "label": "MyCustomPlatformEventChannel"
      }
     }
    
  2. Add a PlatformEventChannelMember that serves as a junction between the xxx__e and the custom channel xxx__chn

    /services/data/v59.0/tooling/sobjects/PlatformEventChannelMember
    
    {
     "FullName": "MyChannel_chn_MyPlatformEvent_e",
     "Metadata": {
     "eventChannel": "MyChannel__chn",
     "filterExpression": "myFilterExpression",
     "selectedEntity": "MyPlatformEvent__e"
     }
    }
    

Where

Notes

From the OP, it looks like you want to filter on recordTypeId but Platform Events don't have record types. You need to filter on values of Checkbox, Date, Datetime, Number, Text and Text Area (long) fields of the Platform Event. Field Considerations

2
  • Thanks a lot, we actually want to Filter dynamically by Custom Field called "Location Id" which will be added to our Custom Platform Event. Each our user will be assigned to some Location. Is there a way to dynamically use the filterExpression for a user who opens the LWC when we subscribe to channel ? Commented Nov 21, 2023 at 18:13
  • @VitaliiDehnerys - I suggest you ask a new question on this site as your use case is different than the original poster. It will then get more attention. Please note How to Ask to get the best response.
    – cropredy
    Commented Nov 21, 2023 at 19:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .