function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Azeez ThummalapalliAzeez Thummalapalli 

Logic written in Platform Event Trigger doesn't work, but the same logic works from ProcessBuilder

I am using `Platform Events`, to fire a webservice(HTTP request) call post transaction commit, let us say Once Account is Created or Account Updated. In the process of doing so, I am able to create/publish Platform Events from the (Account/any Object) Triggers.

Trigger as PlatformEvent Subscriber:
As a Platform Event subscriber, I have written a Trigger on PlatformEvent. Logic written inside the trigger is not completely working, in other words partially working. In detail, in the logic I have added Debug satements as a first line and my further logic is to query a record and send those details in a webservice(HTTP) and update a record based on the HTTPResponse received. 

In this scenario, debug statement is getting executed but neither query nor webservice call happening. I assume this is because of '`Automated Process`' user do not have enough permissions on Object (to query) or Apex class( to invoke)from Trigger. I believe, we do not have any control on this user or it's profile. Correct me if I am wrong?

Work around I have used: The same logic is written in an Invocable method and used ProcessBuilder as PlatformEvent sbscriber. This is working perfectly.

Query: Is it a known issue that we cannot use Triggers as PlatformEvent subscriber? If not, do we have any approach to change Automated Process user's profile permissions? Please help. Thank you in advance.
Leanbridge TechnologiesLeanbridge Technologies
Once you go the multiple triggers per xxx__e approach you need to consider race conditions and record locking in your design. There is no guarantee of which trigger will execute "first" and furthermore, Trigger t might get X records per transaction and Trigger u might get Y (X notequal Y) records per transaction. Both triggers can execute concurrently.
It may also complicate any error retry use cases where the xxx__e event on Trigger t passes whereas Trigger u fails.