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
98765432109876543210 

Trigger question 1

Two objects are there object1 & object2 

 

if object1 is update then automatically object2 is updating, vice versa object2 is update automatically update object1

 

these two objects are in loop conditions.

 

My question is how u will stop the updating. 

Explain me how many ways we can stop the updating..

 

Please reply this question...

simple-forcesimple-force

Hi,

to do this you have to set a static variable in your trigger. In each trigger you run the update only if the trigger wasn't registered before in the static variable.

Pseudo Code: 

 

class TriggerControl

{
    public static Set<String> executedTriggers{
        get{
            if(executedTriggers == null) executedTriggers = new Set<String>();
            return executedTriggers;
    } set;}
}

trigger Object1Trigger on Object1__c (<events>)
{
    if(TriggerControl.executedTriggers.contains('Object1Trigger'))
    {
        TriggerControl.executedTriggers.add('Object1Trigger');
        update ...;
    }
}

 

KrishHariKrishHari

When designing triggers, if proper thought is not given, it can easily go out of control. There are established design concepts and patterns to handle both recursive and non-recursive calls on the apex triggers. The following resource might be helpful for you to architect/design/develop your triggers.

 

Regards,

HK.