0
votes

I'm relatively new to apex, so maybe someone can tell me what I'm doing wrong with this code here. I'm trying to get a trigger to fire when I create a new object. I've created a separate class that it will make a call to.

trigger LearningTriggers on le_Object__c (after insert, after update) {
    if(Trigger.isAfter && (Trigger.isInsert || Trigger.isUpdate)){
        TestingTrigger t = new TestingTrigger();
        t.changeObject(Trigger.new, Trigger.old);
    }
}

This is the method in the class that I am calling with the trigger code.

public with sharing class TestingTrigger {
    public void changeObject(le_Object__c[] newObj, le_Object__c[] oldObj){
        //some code here
    }
}

For some reason, this line in the trigger code "t.changeObject(Trigger.new, Trigger.old);" is throwing this error "Save error: Method does not exist or incorrect signature: [TestingTrigger].changeObject(LIST).

It looks like there might be something wrong with the call to the method, but I'm not sure. I know the name of the method and the number of parameters in the call is correct. Can anyone tell me what's going on here? Is there something that I'm missing?

1
It seams that a file with TestingTrigger is not saved. Refresh it and take a look what you get on server. - Andrii Muzychuk

1 Answers

0
votes

Make the changeObject method a static method

 public static void changeOject(list<le_object__c> newList, list<le_object__c> oldList){
  }

And you do not need to instantiate the class in the trigger, as the method is now static you can directly call the method something like this:

TestingTrigger.changeObject(trigger.new, trigger.old);