I am currently trying to troubleshoot a Platform Events implementation that seems to behave inconsistently. Here's the current architecture:
I have an Apex Trigger on the Account
SObject, where I publish some Platform events. I also have a trigger on that Platform Event SObject, responsible of creating records in Salesforce. I enabled Debug Logs for the Automated Process
, subscribed to the Platform Event using Workbench and started creating some Accounts
to generate some Platform Events.
Expected Outcome:
2 Contacts to be created for each Account
created (due to the Platform Event Apex Trigger)
Actual Outcome:
While looking at the logs generated following the creation of an Account
, every request is generating a Platform Event record successfully. However, it seems like the business logic associated to the Platform Event is executed some times – I can assess this by looking at the output data in Salesforce + missing Automated Process
logs in Salesforce for some of the Platform Events created. I was able to assess that ALL the Events are generated successfully subscribing as well via Workbench and receiving every Platform Events I'd expect.
My questions:
- Is there a reason why Workbench would get notified of an event, but not an Apex Trigger on the exact same Platform Events?
- Is there a chance they are stuck in a queue that is due to be executed at a future time?
- If the previous is possible, is it possible to replay the events that Salesforce skipped?
Thanks
Best Answer
Yes. Triggers on platform events run asynchronously, so that may be a reason. From documentation, refer to the below excerpt.
For:
Yes, because of their asynchronous nature as stated above.
For:
I know if you are subscribed using CometD, you can always use the
ReplayId
available within last 24 hours to fetch the events. In this scenario, I would think that the events are not missed but its only a matter of time when those appear because of their asynchronous nature. Something from the documentation: