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
OdedHarnivOdedHarniv 

Passing a trigger.new to an APEX method

Hi

 

I want to pass trigger.new to an APEX method that will perform some job but I keep getting an error:

Method does not exist or incorrect signature: MatchCandidate.findMatch(LIST<Candidate__c>)

 

my trigger code is:

 

trigger FindMatching on Candidate__c (after insert,after update) {
    
    MatchCandidate.findMatch(trigger.new);
}

 

 

My APEX code is:

 

Public with sharing class MatchCandidate {


 public void findMatch(List<Candidate__c> candidates){

 ///My code here

 }

 

}

 

Can anyone help my figure out what's wrong?

 

Thanks

 

 

Best Answer chosen by Admin (Salesforce Developers) 
Imran MohammedImran Mohammed

You have to create an instance of the class and use that variable to access the method.

 

trigger FindMatching on Candidate__c (after insert,after update) {
    MatchCandidate mc = new MatchCandidate();
    mc.findMatch(trigger.new);
}

 

All Answers

Imran MohammedImran Mohammed

You have to create an instance of the class and use that variable to access the method.

 

trigger FindMatching on Candidate__c (after insert,after update) {
    MatchCandidate mc = new MatchCandidate();
    mc.findMatch(trigger.new);
}

 

This was selected as the best answer
OdedHarnivOdedHarniv

Of course,how could I miss that.

 

Thank you

BritishBoyinDCBritishBoyinDC

You can also just make the method static, and your original code will work...

 

There's a good discussion of the pros and cons here