How to pass Trigger.Old to Apex class in Salesforce?

How to pass Trigger.Old to Apex class in Salesforce?

Sample Code:

Trigger:

trigger Sample on Opportunity (before update, before insert) {
    if (Trigger.isInsert) {
        SampleApexClass.SampleMethod(Trigger.new);
    } else if (Trigger.isUpdate) {
        SampleApexClass.SampleMethod1(Trigger.new, Trigger.old);
    }
}




Apex Class:

global class SampleApexClass () {
    global static void SampleMethod(List<Opportunity> NewOpps) {
        /* trigger code*/
    }

    global static void SampleMethod1(List<Opportunity> NewOpps, List<Opportunity> OldOpps) {
        /* trigger code*/
    }

 }


Cheers!!!

Leave a Reply