Configure the Batch Size for Platform Event Trigger

Configure the Batch Size for Platform Event Trigger

Last Updated on July 6, 2023 by Rakesh Gupta

Big Idea or Enduring Question:

  • How to configure the user and batch size for Platform Event Trigger?


After reading this blog, you’ll be able to:

  • Understand the batch size for platform event trigger
  • Override the default running user for platform event trigger
  • Create the PlatformEventSubscriberConfig via REST API
  • and much more

Business Use case

Jestilla Zetkin is working as a Salesforce Architect at Gurukul On Cloud (GoC). Recently she faced challenges while working with platform events, mainly governer limits. She wants to learn how to configure the batch size for the platform event trigger. In this exercise, we will set up the batch size for the following:

  1. Apex Trigger 
    1. LeadGenerationEventTrigger on Lead_Generation__e 
    2. Batch Size: 50
    3. Running User: Integration User

What is Platform Events?

Event-driven architectures have become very popular in recent years, and for a good reason. It is based on the fire-and-forget pattern. Firing an event and letting each system handle business logic allows you to keep unrelated systems decoupled and can help simplify the architecture.

Platform events enable you to deliver secure, scalable, and customizable event notifications within Salesforce or from external sources. Apps can publish and subscribe to Platform Events on the Salesforce platform using Apex, Flow, or in an external system using CometD. If you want to learn more about Platform Event, check out the Trailhead Module.

What is the Default Batch Size for Platform Event Trigger?

By default, the platform event trigger runs as the Automated Process system user with a batch size of 2,000 event messages. Sometimes it is required to change the user and batch size to bypass governer limits or other challenges.

Salesforce allows you to override the default running user and batch size of a platform event Apex trigger with PlatformEventSubscriberConfig in Tooling API or Metadata API to configure the trigger.

You can specify any active user in the Salesforce org. The trigger runs in a system context with privileges to access all records regardless of the user’s object and field-level permissions. You can specify a custom batch size from 1 through 2,000. The batch size is the maximum number of event messages that can be sent to a trigger in one execution.

Understand PlatformEventSubscriberConfig Object

Let’s take a pause here, familiarize yourself with the PlatformEventSubscriberConfig Tooling API object in Salesforce. It represents configuration settings for a platform event Apex trigger, including the batch size and the trigger’s running user.

Field Name
BatchSize A custom batch size, from 1 through 2,000, for the platform event Apex trigger. The batch size corresponds to the maximum number of event messages that can be sent to a trigger in one execution. The default batch size is 2,000 for platform event triggers.
DeveloperName The unique name for the PlatformEventSubscriberConfig object.
MasterLabel Label for PlatformEventSubscriberConfig. In the UI, this field is Platform Event Subscriber Configuration.
PlatformEventConsumerId The ID of the platform event Apex trigger to configure.
UserId The ID of the user that the platform event Apex trigger runs as. By default, the platform event trigger runs as the Automated Process entity. Setting the running user to a specific user has these benefits:

  • Records are created or modified as this user.
  • Records with OwnerId fields have their OwnerId fields populated to this user when created or modified.
  • Debug logs for the trigger execution are created by this user.
  • You can send email from the trigger, which isn’t supported with the default Automated Process user.

PlatformEventSubscriberConfig components have the suffix .platformEventSubscriberConfig and are stored in the PlatformEventSubscriberConfigs folder.

This PlatformEventSubscriberConfig component has the label LeadGenerationEventTriggerConfig. It contains the configuration of a platform event trigger, LeadGenerationTrigger, and specifies the batch size and user.

<?xml version="1.0" encoding="UTF-8"?>
<PlatformEventSubscriberConfig xmlns="">

Guided Practice (We-do):

To add a configuration, perform a POST request as mentioned below:

  1. Open the Workbench and log in with your Trailhead playground username and password.
  2. Make sure that you’ve selected the Production for Environment option.
  3. Navigate to Utilities tab and select the REST Explorer option.
  4. Select the following options:

    1. Choose an HTTP method to perform on the REST API service URI below: POST
    2. URL: /services/data/v58.0/tooling/sobjects/PlatformEventSubscriberConfig
    3. Body: Provide the values in the request body. This example request configures an existing trigger with the batch size of 50 and specifies the ID of a running user.
      1. {
        “BatchSize”: “50”,
        “PlatformEventConsumerId”: “01qB0000000Zcug”,
        “UserId”: “005B00000015gt8”
      2. Where:
        1. 01qB0000000Zcug, Apex trigger on Lead_Generation__e
        2. 005B00000015gt8, is user Id of Integration User
    4. Click Execute.
  5. You can query retrieve the configurations in your org with SOQL. If querying from the Developer Console Query Editor, ensure you select Use Tooling API. This example query retrieves all configurations set up in your Salesforce org.

Formative Assessment:

I want to hear from you!

What is one thing you learned from this post? How do you envision applying this new knowledge in the real world? Feel free to share in the comments below.

Have feedback, suggestions for posts, or need more information about Salesforce online training offered by me? Say hello, and leave a message!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.