My current template for trigger class, handler and test using Switch statement and Execution controll in custom settings.

Disable selected type of trigger for example before update.

See Trigger Execution Controller article for details.

 

Class: Case_Trigger

/**
 * @author      Paweł Woźniak This email address is being protected from spambots. You need JavaScript enabled to view it.
 * @created     2019-05-16
 * @updated     2019-05-16
 * @description Case Trigger
*/
trigger Case_Trigger on Case(before insert, before update, before delete, after insert, after update, after delete, after undelete) {

    TriggerExecutionController tec = new TriggerExecutionController('Case_Trigger');
    System.TriggerOperation triggerEvent = Trigger.operationType;

    switch on triggerEvent {

        /***** INSERT ******/

        when BEFORE_INSERT {
            if (tec.beforeInsertDisabled) { return; }
            //System.debug('Before insert trigger');
            //Avaliable records: Trigger.new

        }

        when AFTER_INSERT {
            if (tec.afterInsertDisabled) { return; }
            //System.debug('After insert trigger');
            //Avaliable records: Trigger.new, Trigger.newMap

        }

        /***** UPDATE ******/

        when BEFORE_UPDATE {
            if (tec.beforeUpdateDisabled) { return; }
            //System.debug('Before update trigger');
            //Avaliable records: Trigger.new, Trigger.newMap, Trigger.oldMap

        }

        when AFTER_UPDATE {
            if (tec.afterUpdateDisabled) { return; }
            //System.debug('After update trigger');
            //Avaliable records: Trigger.new, Trigger.newMap, Trigger.oldMap

        }

        /***** DELETE ******/

        when BEFORE_DELETE {
            if (tec.beforeDeleteDisabled) { return; }
            //System.debug('Before delete trigger');
            //Avaliable records: Trigger.oldMap

        }

        when AFTER_DELETE {
            if (tec.afterDeleteDisabled) { return; }
            //System.debug('After delete trigger');
            //Avaliable records: Trigger.oldMap

        }

        when AFTER_UNDELETE {
            if (tec.afterUnDeleteDisabled) { return; }
            //System.debug('Before undelete trigger');
            //Avaliable records: Trigger.new, Trigger.newMap

        }
    }
}

 

Class: Case_TriggerHandler

/**
 * @author      Paweł Woźniak This email address is being protected from spambots. You need JavaScript enabled to view it.
 * @created     2019-05-16
 * @updated     2019-05-16
 * @description Case Trigger Handler
*/
public without sharing class Case_TriggerHandler {

    // Before Update

    // Before Insert

    // After Update

    // After Insert

}

 

Class: Case_Trigger_Test

/**
 * @author      Paweł Woźniak This email address is being protected from spambots. You need JavaScript enabled to view it.
 * @created     2019-05-16
 * @updated     2019-05-16
 * @description Case Trigger Test
*/
@isTest
private class Case_Trigger_Test {

    // Before Update

    // Before Insert

    // After Update

    // After Insert

}

 

 

   
© Paweł Woźniak