Configure the User and Batch Size for Your Platform Event Trigger

You can override the default running user and batch size of a platform event Apex trigger. By default, the trigger runs as the Automated Process system user with a batch size of 2,000 event messages. Configuring the user and batch size enables you to bypass some limitations that sometimes arise from using the defaults. For example, record system and OwnerId fields are populated as the specified user. And setting a batch size smaller than 2,000 can help avoid hitting Apex governor limits.

Where: This change applies to Enterprise, Performance, Unlimited, and Developer editions.

How: Configure a platform event trigger using PlatformEventSubscriberConfig in Metadata API or Tooling API.

This example shows the configuration of OrderEventTrigger using Metadata API. The user is set to user@example.com and the batch size is 200.

<?xml version="1.0" encoding="UTF-8"?>
<PlatformEventSubscriberConfig xmlns="http://soap.sforce.com/2006/04/metadata">
    <platformEventConsumer>OrderEventTrigger</platformEventConsumer>
    <batchSize>200</batchSize>
    <masterLabel>OrderEventTriggerConfig</masterLabel>
    <user>user@example.com</user>
    <isProtected>false</isProtected>
</PlatformEventSubscriberConfig>