Skip to main content

I'm working with Platform Events in Salesforce and have a question about how event delivery is handled with respect to heap size limits in Apex triggers. 

 

I understand the following: 

 

Each Platform Event can be up to 1 MB in size. 

 

An Apex trigger that subscribes to a Platform Event runs synchronously, and the maximum heap size for synchronous Apex transactions is 6 MB. 

 

It's possible to configure the batch size (e.g., 100) for a Platform Event subscriber via PlatformEventSubscriberConfig. 

 

 

Here’s my concern: 

 

If I publish 100 events, each of size close to 1 MB, and my trigger is configured with a batch size of 100, that would theoretically mean 100 MB worth of data is being delivered to a single trigger execution. But this clearly exceeds the 6 MB heap limit for synchronous Apex. 

 

❓ My question is: 

 

How does Salesforce handle this under the hood? 

 

Does the Platform Event delivery system automatically split the batch into smaller chunks that stay within the synchronous heap limit? 

 

Can I trust that the Apex trigger will never receive more events than it can handle without hitting heap size errors? 

 

Is there any official documentation or internal behavior description about how this batching/delivery mechanism works for large Platform Events? 

 

 

Thanks in advance for any clarification or resources!

3 réponses
0/9000