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
Dan LordDan Lord 

If a trigger handler calls a static method, what happens when another of the same type of trigger fires before that method finishes execution?

All the samples I've seen of Apex trigger handlers have them calling static methods in a helper/service class. What happens when a second trigger of the same type (say after insert) on the same object happens before that static method has finished executing? Will the second trigger call that static method and take over its execution - changing records, variables, etc?

This reveals my ignorance, but I've tried to figure this out on my own (using Google, etc.) without success.

Help/guidance/explanation would be greatly appreciated.
Best Answer chosen by Dan Lord
Dan LordDan Lord
Thank you for your reply, Anudeep, but you misunderstood what I wrote. I was asking about the same trigger code being triggered by a subsequent trigger event (insert, etc.)

I did receive an answer from another forum where I posted this question. The short answer is, "any Apex code called by each trigger invocation has static variables that are scoped to the transaction." So, my worry was baseless.

All Answers

AnudeepAnudeep (Salesforce Developers) 
As far as I know, it is not recommended to have multiple triggers for the same event in the first place because Salesforce doesn't guarantee of the order of execution of triggers if there are more than one. So we can't say for sure by which trigger executes the static method

See order of execution here

Let me know if it helps
Dan LordDan Lord
Thank you for your reply, Anudeep, but you misunderstood what I wrote. I was asking about the same trigger code being triggered by a subsequent trigger event (insert, etc.)

I did receive an answer from another forum where I posted this question. The short answer is, "any Apex code called by each trigger invocation has static variables that are scoped to the transaction." So, my worry was baseless.
This was selected as the best answer