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
sudarshan Reddy 25sudarshan Reddy 25 

After update effect on triggers.

I have 2 triggers on Lead. At first it was like one before update, second with after update triggers. Later We have changed both the triggers to AFTER UPDATE. Now someof the functionalities are not working. Is AFTER update on both the triggers affecting?? If, YES please give your suggestios to resolve this.
 
Shiva RajendranShiva Rajendran
Hi Sudarshan,
As per my knowledge, both the triggers would be triggered whenever an update happens.But we can't control the order of trigger execution out of these two.
You can better the best practise in salesforce by having two delegate methods and calling two methods in the trigger.

For example :

Trigger afterupdateTriger on contact(after update)
{
TriggerDelegate.logic1(Trigger.new);
TriggerDelegate.logic2(Trigger.new);

}

class TriggerDelegate
{

   public static void logic1(List<Id> contactIds)
{

}

public static void logic2(List<Id> contactIds)
{

​}


}


I hope this approach will help you resolve.

Let me know if you need further help.

Thanks and Regards,
Shiva RV
Shamsi 110Shamsi 110
change your code in this way.

//Handler
Public Class YourObjectHandler{

public static void LogicAfterUpdate(list<Projects__c> newRecords,Map<Id,Projects__c> OldRecordsMap)
//Your Logic
}

public static void LogicBeforeUpdate(list<Projects__c> newRecords,Map<Id,Projects__c> OldRecordsMap)
//Your Logic
}



//Trigger
trigger ProjectTrigger on Projects__c (before update,after update) {

    if(trigger.isUpdate && trigger.IsAfter ){
        LogicAfterUpdate(//Send old and new map that you need);
        //LogicAfterUpdate(Trigger.new,Trigger.oldMap);
    }
  
    else if(trigger.isUpdate && trigger.IsBefore){
        LogicBeforeUpdate(//Send old and new map that you need);
        //LogicBeforeUpdate(Trigger.new,Trigger.oldMap);
    }    


}


Please mark it as solved if this solves your problem