I am looking for a generic solution that would allow instead of creating triggers for each platform event to create one and in some way forward to it. If this even possible and what pattern should I use?
1 Answer
You have to create one per event type, but you can consolidate the logic to a single utility class:
trigger demoEvent1 on Event1__e (after insert) {
TriggerUtil.handleEvent(Trigger.new);
}
trigger demoEvent2 on Event2__e (after insert) {
TriggerUtil.handleEvent(Trigger.new);
}
The class itself would just accept a generic list of records:
public class TriggerUtil {
public static void handleEvent(sObject[] events) {
// Do stuff here //
}
}