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
CYTechCYTech 

Recursive Triggers

Hey Everyone,

 

I am having difficulty running some tests with triggers.

 

First trigger updates an Event object when an Opp has been updated.

The second trigger tries to update the Opp when the Event has been updated.

 

Just trying to keep information accurate on each object, however as you can imagine if I update from either trigger it runs the trigger for the other object and I get a recursive trigger execution.

 

Both are running 'after update'.

 

Is there a simple method or way to update each record without it having to trigger the other? Maybe it is as simple as checking if the values match before running an update?

 

Looking for some guidence on the workflow, or method to accomplish keeping two records up to date without having recursive triggers running.

 

I appreciate any help! :)

Shoby Abdi.ax910Shoby Abdi.ax910

One possible way is to try an extrinsic locking method. The simplest way is to have a static Boolean isRunning value set on a public static class. When the opportunity is being updated, set that isRunning value to true (it should by default be false), then when the other trigger is about to run, verify the value of that static boolean.

 

 

public class StaticUtil {
public static Boolean isRunning = false;
}

 

trigger EventTrigger on Event (after update) {
 StaticUtil.isRunning = true;
 //Run your code with DML
 StaticUtil.isRunning = false;
}

 

 

 

trigger OpportunityTrigger on Opportunity(after update) {
if(!StaticUtil.isRunning) {
//run your code
}
}

 

 

 

CYTechCYTech

Nifty idea, I will give it a try, thanks!

CYTechCYTech

Worked like a charm! I appreciate it!  :)