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
ethanoneethanone 

Passing array from trigger to class method

I'm new to Apex, so I hope there is a simple answer here. I've got a class with two methods that I'm trying to pass the trigger.new results to from two different triggers respectively.  I think I'm doing the same thing with both triggers and methods, but one trigger works fine and the other has a save error "Method does not exist or incorrect signature: closeOpportunity.insertNewProperty(LIST:SOBJECT: Opportunity)". Here is the basic declaration for the class (I've removed the guts for simplicity): 

 

public with sharing classcloseOpportunity {

      public static voidcheckAcceptedOffers(Opportunity[] opps){

      }

     

      public static voidinsertNewProperty(Opportunity[] opps){

      }

} 

Here are the two triggers respectively:

This one works:

 triggercheckOpportunityForClose on Opportunity (before insert, before update) {

      Opportunity[] opps = trigger.new;

      closeOpportunity.checkAcceptedOffers(opps);

}

 

This one does not work: 

 triggergenerateNewProperty on Opportunity (after insert, after update) {

      Opportunity[] opps = trigger.new;

      closeOpportunity.insertNewProperty(opps);

}

 

I was trying to do all of the processing at the class method level, so I was just passing the entire list to the class.  If this is bad practice, let me know.  If I'm passing the list the wrong way, please let me know what the correct way is. Why does one work an the other not work? Thanks in advance.

wesnoltewesnolte

Hey

 

Just a guess, but I think that trigger.new contains a strange value. Try putting a debug message in and tell us what you get e.g.

 

 triggergenerateNewProperty on Opportunity (after insertafter update) {

      Opportunity[] opps = trigger.new;

System.debug(opps); 

      closeOpportunity.insertNewProperty(opps);

} 

 

Cheers,

Wes 

OnkiOnki
Is it giving runtime error or before saving code you are getting error?