25 November, 2026

Controlling Salesforce Platform Event Subscribers with PlatformEventSubscriberConfig

by Ana Urumovska

As Salesforce applications become more integrated and business processes become more complex, asynchronous communication becomes an important part of application architecture. Instead of executing every operation within the same transaction, we can use Platform Events to decouple processes and allow different parts of an application to communicate through event messages.

Platform Events provide a powerful way to achieve this. They allow one process to publish an event while another process subscribes to it and handles the necessary business logic independently.

However, there is one important detail that is easy to overlook when implementing Platform Events: the user context in which the subscriber executes. By default, Apex triggers subscribing to Platform Events run under the Automated Process user. While this works for many scenarios, there are situations where having a dedicated user responsible for processing events provides better control, visibility, and flexibility.

This is where PlatformEventSubscriberConfig comes in. In this post, we'll look at how Platform Event subscribers work, why execution context matters, and how to configure a dedicated user to execute a subscriber.


Understanding Platform Events

Platform Events are part of Salesforce's event-driven architecture. They allow different components and systems to communicate without requiring direct dependencies between them. The concept is relatively simple:

  • A publisher creates and publishes an event.

  • Salesforce stores the event in the event bus.

  • One or more subscribers listen for that event.

  • When an event is received, the subscriber executes the appropriate business logic.

For example, imagine an application where an Opportunity is successfully closed. Instead of performing every follow-up operation inside the same transaction, we can publish an OpportunityClosed__e event.

A separate Apex trigger can subscribe to that event and handle additional operations, such as creating related records, notifying another system, or initiating a follow-up process.

The publisher doesn't need to know how the subscriber handles the event. This separation makes the application more flexible and easier to maintain.

How Platform Event Subscribers Execute

When subscribing to a Platform Event using an Apex trigger, Salesforce handles the event delivery and invokes the trigger asynchronously.

Unlike standard object triggers, Platform Event triggers don't execute in the same transaction that published the event. They run in a separate transaction, which means the publishing process doesn't need to wait for the subscriber to finish its work. Consider the following example:


The trigger acts as an entry point and delegates the actual business logic to a service class.

This keeps the trigger simple and allows the processing logic to be reused and tested independently.

However, there's something important happening behind the scenes.

By default, Salesforce executes Platform Event Apex triggers using the Automated Process user.

This is different from the user who published the event. Even if a regular Salesforce user publishes the event, the subscriber executes under its own execution context.

For some applications, this default behavior is perfectly fine. But what happens when we need the subscriber to execute under a specific Salesforce user?

Why Use a Dedicated Execution User?

There are several reasons why we might want to configure a dedicated user for Platform Event processing.

It provides better visibility and auditing. Records created or modified by the subscriber can reference the configured user in their system fields. Debug logs are also associated with that user.

It can help when certain operations depend on a specific user context. For example, sending email messages directly from a Platform Event trigger isn't supported with the default Automated Process user because it doesn't have an email address.

It provides a clearer separation between regular user activity and automated processing.

Instead of relying on the default Automated Process user, we can create a dedicated Salesforce user specifically for asynchronous processing. This makes it easier to identify which operations belong to a particular integration or background process.


Introducing PlatformEventSubscriberConfig

Salesforce provides PlatformEventSubscriberConfig to customize the configuration of an Apex Platform Event subscriber.

It allows us to override two important settings:

  • User: Defines which Salesforce user executes the subscriber.

  • Batch Size: Defines the maximum number of event messages delivered to the trigger in a single execution.

By default, a Platform Event trigger runs as Automated Process and receives a maximum batch size of 2,000 events.

Using PlatformEventSubscriberConfig, we can change these defaults to better suit our application's requirements. The configuration can be managed through the Tooling API or Metadata API.


Configuring a Dedicated Subscriber User

Let's walk through a practical example.

Assume we already have a Platform Event called OpportunityClosed__e, and an Apex trigger called OpportunityClosedTrigger.

We want this trigger to execute using a dedicated Salesforce user instead of Automated Process.

1. Create a Dedicated Salesforce User

First, we create a Salesforce user that will be responsible for executing the subscriber. For example, we could create a user named:Platform Event Integration User

This user should be active and configured with the appropriate Salesforce license, profile, and permission sets required by the application. Although the trigger executes in system context, using a dedicated user is still useful for record ownership, auditing, debug logs, and sharing behavior. It's also a good practice to grant only the access and permissions necessary for the intended responsibilities

2. Create the Subscriber Configuration

Next, we create a PlatformEventSubscriberConfig metadata component.

For our example, the configuration would look like this:

<?xml version="1.0" encoding="UTF-8"?> <PlatformEventSubscriberConfig xmlns="http://soap.sforce.com/2006/04/metadata"> <platformEventConsumer> OpportunityClosedTrigger </platformEventConsumer> <masterLabel> Opportunity Closed Trigger Config </masterLabel> <user> platform.event.integration@example.com </user> <batchSize>200</batchSize> <isProtected>false</isProtected> </PlatformEventSubscriberConfig>

There are a few important fields here:

  • platformEventConsumer identifies the Apex trigger that subscribes to the Platform Event.

  • masterLabel provides a descriptive name for the configuration.

  • user specifies the username of the Salesforce user that should execute the trigger.

  • isProtected defines the maximum number of events processed in a single trigger execution.

  • isProtected controls whether the metadata component is protected.

In this example, we're configuring the trigger to execute as our dedicated integration user and process a maximum of 200 events per execution. The batch size is configurable between 1 and 2,000. Choosing an appropriate value depends on the complexity of the processing logic and the governor limits involved. It's generally better to test different values rather than automatically choosing the smallest possible batch size.

3. Deploy the Configuration

Once the metadata file is created, we can deploy it to Salesforce using the Metadata API. This can be done through Salesforce CLI and Visual Studio Code, just like other Salesforce metadata components.

The important thing to remember is that the configuration is associated with a specific Apex trigger, not simply with the Platform Event itself. This means that if multiple triggers subscribe to the same event, each subscriber can have its own configuration.

4. Verify the Subscriber Configuration

After deployment, we can verify the configuration directly in Salesforce.

Navigate to: Setup → Platform Events → Select Your Platform Event → Subscriptions

The Subscriptions related list displays the Apex triggers listening to the selected event. From there, we can inspect the subscriber and verify its configured user, batch size, and current subscription state. This is also a useful place to monitor whether the subscriber is running, suspended, or in an error state.

If the subscriber was already running when the configuration changed, Salesforce may require us to suspend and resume the trigger for the new settings to take effect immediately.

Important Considerations

Although configuring a dedicated subscriber user is relatively straightforward, there are a few things worth keeping in mind.

Execution Context and Security

Running a subscriber as a specific user doesn't mean Apex automatically enforces all that user's permissions.

Apex triggers execute in system context. If record-level sharing needs to be respected, we should use appropriate sharing declarations in the classes responsible for processing the events.

We should also explicitly consider CRUD and field-level security where required.

Batch Size and Governor Limits

Platform Event triggers can receive up to 2,000 events in a single execution by default.

If the processing logic performs multiple queries or DML operations, a smaller batch size might help avoid governor limit exceptions.

However, reducing the batch size too much can negatively affect processing throughput.

Monitoring and Debugging

One advantage of using a dedicated execution user is that debug logs are associated with that user rather than Automated Process. This makes troubleshooting easier, especially when multiple asynchronous processes are running in the same Salesforce org.

Deployment and Configuration

Since PlatformEventSubscriberConfig is metadata, it should be included in the deployment process and managed alongside the Apex trigger it belongs to. It's also important to verify that the configured user exists and is active in the target environment. Usernames can differ between development, testing, and production environments.

Final Thoughts

Platform Events are a great way to build loosely coupled and scalable Salesforce applications. They allow different processes to communicate asynchronously without introducing unnecessary dependencies.

However, implementing an event-driven architecture involves more than simply publishing and subscribing to events. Understanding the subscriber's execution context is equally important.

PlatformEventSubscriberConfig provides a straightforward way to control which user executes an Apex Platform Event trigger and how many events are processed in each execution. Using a dedicated user can improve traceability, make debugging easier, and provide more predictable behavior when dealing with automated processes. It's a relatively small configuration, but one that can make a meaningful difference when building more complex Salesforce integrations and asynchronous workflows.

Share: