Tuesday, 16 August 2022

Configure the Running User and Batch Size for Your Platform Event Trigger

 Hi,

Here we are going to learn how to Configure the Running User and Batch Size for Your Platform Event Trigger.

By default, the trigger on Platform Event runs as the Automated Process system user with a batch size of 2,000 event messages. 

By configuring a platform event trigger using PlatformEventSubscriberConfig in Metadata API or Tooling API we can override the running user and batch size of a Platform Event Apex Trigger.

Benefits:

Configuring the user and batch size enables you to bypass some limitations that sometimes arise from using the defaults.

Eg:

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.

Run the code block as a specified user which is written under Platform Event Trigger.

How to Configure PlatformEventSubscriberConfig?

  • Create a folder called "PlatformEventSubscriberConfigs"
  • Create a file with the suffix .platformEventSubscriberConfig as shown below.

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

Here 
AccountEventTrigger  is the name of the Platform Event Trigger
200  is batch size (Batch size 1 is not recommended)
AccountEventTriggerConfig is the name of the PlatformEventSubscriberConfig

Create package.xml as shown below.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">   
     <types>
        <members>AccountTriggerEventConfig</members>
        <name>PlatformEventSubscriberConfig</name>        
    </types>
    <version>55.0</version>
</Package>

Once we create both as shown below then create any folder include the following and zip.





Now open Workbench then chooses the Deploy option and then select the zip.





Now click on Deploy then it will be successful.


Reference:
https://help.salesforce.com/s/articleView?id=release-notes.rn_messaging_trigger_config.htm&type=5&release=230

https://developer.salesforce.com/docs/atlas.en-us.api_meta.meta/api_meta/meta_platformeventsubscriberconfig.htm




No comments:

Post a Comment

What’s the difference between Einstein Article Recommendations and Suggested Articles?

How Does Einstein Article Recommendations Work? Einstein Article Recommendations helps support agents resolve customer cases efficiently by ...