I am trying to build an Enterprise level framework on the top of Platform Events accessible to our external vendors, internal API's and internal developers. After doing a deep analysis on the capabilities, we came around the following road blocks which won't be applicable or doesn't has solution when we go live with the Platform Events Framework.
Is there anything I should be wary about apart from the list mentioned below ? Does anyone has prior experience of building a developer oriented framework on the top of Platform Events, making it easier for development.
- Fatal Error - User's need explicit access to classes if getting invoked by a Flow. Platform events runs as Automated Process user and if it runs a trigger which starts a flow which calls an invocable Apex. It will fail at "Flow fails: FLOW_ELEMENT_ERROR Profile does not have access to: no invocable"
How to replicate :
- Publish Platform Event Xxxx__e
- Subscribe to Xxxx__e with trigger, save data in sObjects Foo__c (running user = automated process)
- Process Builder on Foo__c creation calls invocable apex class NopInvocable.cls
Here's a link -
- Exception Handling - Platform Events fired triggers executes as Automated Process user, if it exceeds CPU Limits - no notification will be sent to developers even though you've Apex Exception Email Configured or Apex Warning Emails configured.
This means that if our PE is bulkified and one event in batch fails (Apex CPU or Heap) , the other members will fail and will be undetected.
Possible Workaround : have a logging object - track job id , status and error message, move your core logic in queueable, from the trigger fire the core logic and synchronously store the log record, you'll lose chaining of records and possibly replay of your logic.
This error will make our Production System with no notifications to uncatchable limit exception.
Other workaround : ○ Use EventLogFile to track error but it’s a part of Shield so extra $$. ○ Use setResumeCheckpoint helps in retry from last limit exception.
API Calls - How do we hold the event published by external app and retrieve within 24 hours to update the record with the architecture.
Bulkification - Due to optimistic tuning - PE event processing doesn't gets limited to 200 records per transaction, rather it goes to 2000. Meaning Trigger.new.size() can be up to 2000 - meaning even with careful bulkification the potential to hit Apex DML Limits will be higher. List of sObjects of Size 500 having multiple workflows, flows etc. will fail on DML Limit. This can only be addressed if we have proper checkpoints setting.
API Calls - Scenario of invoking API Calls directly from Platform Events won't work. Also, there's no way to control number of events that are processed in each trigger. So we would end up using a Custom Object Architecture.
Audit & Maintenance - The ability to know the list of subscribers to a particular event isn't defined yet in Platform Events.
Merge Fields and Visualforce Templates - As running via Automated Users, Platform Events do impose severe issues on merge fields wherein the templates aren't accessible likewise the ability to fetch the most recent (changes during same transaction).
Refreshed Sandbox Issue - In the past, there have been issues with PE requiring subscriber classes to be complied after Sandbox Refresh within Sandbox. This was ideally fixed in Win 19, but still come around for some users or the other.