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




Tuesday 2 August 2022

How to get the current recordId in LWC quick action?

Hi,

To get the current recordId when we create a quick action with LWC  we have to use the below code snippet.



_recordId;
set recordId(recordId) {
    if (recordId !== this._recordId) {
        this._recordId = recordId;


Note:
LWC quick actions don’t pass in recordId in connectedCallback()




Reference:


How to include a screen flow in a Lightning Web Component

 Hi, Assume  you have a flow called "Quick Contact Creation" and API Name for the same is "Quick_Contact_Creation". To i...