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
HNT_NeoHNT_Neo 

help with understanding this apex trigger

Can someone help me understand what this apex trigger is doing? Someone set this up in our org, in the event object and having a hard time understanding what its doing: 
 
trigger Events on Event (before insert, before update, after insert, after delete) 
{

  if ( trigger.isBefore)
  {
    if ( trigger.isInsert || trigger.isUpdate)
    {
      if(AccountCallRollup.batch_update_running!=true)
        {
        //Events.ActivityCallRollup(Trigger.new);
        }

      Events.PopulateActivityFields( trigger.new );
    //5/5/2018: Consolidated from separate trigger
      Events.Event_User_field_from_Assigned_To_Before(Trigger.new);
    }

    //if(trigger.isDelete && AccountCallRollup.batch_update_running!=true)
    //  {
    //  Events.ActivityCallRollup(Trigger.old);
    //  }

  }

  if ( trigger.isAfter)
  {
    if ( trigger.isInsert || trigger.isUpdate)
    {
    //5/5/2018: Consolidated from separate trigger
      Events.Event_User_field_from_Assigned_To_After(Trigger.new);
    if(AccountCallRollup.batch_update_running!=true)
      {
      //6/22/18: Turn off immediate rollup
      //Events.ActivityCallRollup(Trigger.new);
      }
    } 
  }

    if(AccountCallRollup.batch_update_running!=true && trigger.isDelete)
      {
      //6/22/18: Turn off immediate rollup
      //Events.ActivityCallRollup(Trigger.old);
      }


}

 
Best Answer chosen by HNT_Neo
Dhanraj Poojary 18Dhanraj Poojary 18
As far as I can understand there are two classes namely Events and AccountCallRollup

Code Block -
if(AccountCallRollup.batch_update_running!=true)
        {
         //Events.ActivityCallRollup(Trigger.new);
        }
Execution - There is Static Boolean Variable named batch_update_running in AccountCallRollup Class which if set false then the If block would be executed (If the action is performed from batch Context stop Trigger from firing or in other words Skip Trigger Execution)

Code Block - 
     Events.PopulateActivityFields( trigger.new );
    //5/5/2018: Consolidated from separate trigger
     Events.Event_User_field_from_Assigned_To_Before(Trigger.new);
Execution - PopulateActivityFields and Event_User_field_from_Assigned_To_Before are two Static methods of Events Class which accepts List<Events> as Parameter
Since Trigger.new returns List<Event>

Code Block -
      //5/5/2018: Consolidated from separate trigger
      Events.Event_User_field_from_Assigned_To_After(Trigger.new);
Execution - Event_User_field_from_Assigned_To_After is again a Static Method which accepts List<Events> as Parameter

Code Block -
     if(AccountCallRollup.batch_update_running!=true)
      {
      //6/22/18: Turn off immediate rollup
      //Events.ActivityCallRollup(Trigger.new);
      }
Execution - There is Static Boolean Variable named batch_update_running in AccountCallRollup Class which if set false then the If block would be executed (If the action is performed from batch Context stop Trigger from firing or in other words Skip Trigger Execution)

Code Block - 
      if(AccountCallRollup.batch_update_running!=true && trigger.isDelete)
      {
      //6/22/18: Turn off immediate rollup
      //Events.ActivityCallRollup(Trigger.old);
      }
Execution - There is Static Boolean Variable named batch_update_running in AccountCallRollup Class which if set false then the If block would be executed provided it is Trigger.IsDelete Context (If the action is performed from batch Context stop Trigger from firing or in other words Skip Trigger Execution)

Basically as per my understanding you are seeing this since someone has Setup a Batch Job to leverage the functionality of Events and AccountCallRollup and he has setup flags to avoid the trigger being fired if he is Performing Insert,Update and Delete Functionality from Batch Context.
So basically it is skipping the trigger execution when the operation is performed from a batch context

All Answers

Dhanraj Poojary 18Dhanraj Poojary 18
As far as I can understand there are two classes namely Events and AccountCallRollup

Code Block -
if(AccountCallRollup.batch_update_running!=true)
        {
         //Events.ActivityCallRollup(Trigger.new);
        }
Execution - There is Static Boolean Variable named batch_update_running in AccountCallRollup Class which if set false then the If block would be executed (If the action is performed from batch Context stop Trigger from firing or in other words Skip Trigger Execution)

Code Block - 
     Events.PopulateActivityFields( trigger.new );
    //5/5/2018: Consolidated from separate trigger
     Events.Event_User_field_from_Assigned_To_Before(Trigger.new);
Execution - PopulateActivityFields and Event_User_field_from_Assigned_To_Before are two Static methods of Events Class which accepts List<Events> as Parameter
Since Trigger.new returns List<Event>

Code Block -
      //5/5/2018: Consolidated from separate trigger
      Events.Event_User_field_from_Assigned_To_After(Trigger.new);
Execution - Event_User_field_from_Assigned_To_After is again a Static Method which accepts List<Events> as Parameter

Code Block -
     if(AccountCallRollup.batch_update_running!=true)
      {
      //6/22/18: Turn off immediate rollup
      //Events.ActivityCallRollup(Trigger.new);
      }
Execution - There is Static Boolean Variable named batch_update_running in AccountCallRollup Class which if set false then the If block would be executed (If the action is performed from batch Context stop Trigger from firing or in other words Skip Trigger Execution)

Code Block - 
      if(AccountCallRollup.batch_update_running!=true && trigger.isDelete)
      {
      //6/22/18: Turn off immediate rollup
      //Events.ActivityCallRollup(Trigger.old);
      }
Execution - There is Static Boolean Variable named batch_update_running in AccountCallRollup Class which if set false then the If block would be executed provided it is Trigger.IsDelete Context (If the action is performed from batch Context stop Trigger from firing or in other words Skip Trigger Execution)

Basically as per my understanding you are seeing this since someone has Setup a Batch Job to leverage the functionality of Events and AccountCallRollup and he has setup flags to avoid the trigger being fired if he is Performing Insert,Update and Delete Functionality from Batch Context.
So basically it is skipping the trigger execution when the operation is performed from a batch context
This was selected as the best answer
HNT_NeoHNT_Neo
Dhanraj thank you for reviewing this code. I now see more clearly and have located the other Apex classes which are extremely more sophisticated. However, it seems the code being written has over complicated our process. It has also created other issues if misfiring record updates and the end user experience is suffering. Once again, thank you for your detailed response.
Dhanraj Poojary 18Dhanraj Poojary 18
No Worries. Happy Coding.
HNT_NeoHNT_Neo
Quick question, do you think that by looking at the //, that they are commenting those lines out and adding new events to see if that will work? Reason I ask is because issues are showing up in Activites and erroring out when users try saving records.
Dhanraj Poojary 18Dhanraj Poojary 18
Maybe. There are chances that their development is not complete yet.