0

I saw a piece of code and started to get confused. Help me out if you have any experience with the same.

I have a trigger on the Lead object. So, When Lead Email get's update, I publish a platform event to update some other record.

Once above platform event [ myEvent__e ] is published. The trigger on this myEvent__e gets executed.

This trigger on myEvent__e updates a record of Object [ UpdatedEmails__c ] that is not related to lead object. It just takes some info of lead records from the received platform event.

Hope that scenario is clear.

Now question is If DML Inside my second trigger logic [ myEvent__e ] throws an exception. ( with no try/catch block ). Will the transaction Rollback? Or will the lead update revert to its original state?

My Findings: I observed that The first trigger logic on lead till firing platform event is coming under my user logs. And After that, debug logs are coming under automation user.

That means they are two different transactions and exceptions will not rollback completely.

Thanks in advance!

2
  • What's the state of platform event trigger? is it publish immediately or publish after commit? Apr 2 at 10:02
  • Hi @PranayJaiswal It is published after commit. What about if the DML in the second trigger which caused the exception was the 2nd DML of the method. First DML changes will not commit right ? Apr 2 at 10:41
2

Assuming your platform event is selected as publish after commit , then the original transaction for lead has already been committed into the database, and thus any exception into platform event trigger won't rollback anything that caused it to fire in the first place.

1
  • 1
    Even with publish immediately, the platform event is handled in a separate transaction. In this case the initial transaction doesn't need to succeed for the platform event to be processed.
    – Phil W
    Apr 2 at 17:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.