I'm trying move majority of my code to Apex classes and minimize on the trigger code. When I pass Trigger.old and Trigger.new to class methods, I keep getting this error:
Compilation error: Method does not exist or incorrect signature: [CLTools.processRecords(List<Lead>, List<Lead>, CLFieldAssignments.triggerAction)]
Trigger
trigger CLFieldAssignments on Lead( before insert, before update ) {
public enum triggerAction { beforeInsert, beforeUpdate, afterInsert, afterUpdate }
CLTools clt = new CLTools();
// Handle beforeInsert
if( Trigger.isInsert && Trigger.isBefore ) {
clt.processRecords( Trigger.new, Trigger.old, triggerAction.beforeInsert );
}
}
Apex Class
public with sharing class CLTools {
// Trigger states
public enum triggeredAction { beforeInsert, beforeUpdate, afterInsert, afterUpdate }
// Constructor
public CLTools() {}
// Process
public void processRecords( List<Lead> newLeads, List<Lead> oldLeads, triggeredAction ta ) {
// Insert
if( ta == triggeredAction.beforeInsert ) {
}
// Update
if( ta == triggeredAction.beforeUpdate ) {
}
}
}
Based on various recommendations via Google searches, I've tried out all combinations of Lists & Arrays to try and match the method signatures:
- Lead[]
- List
- List
- List
What is the correct signature for receiving Triggers? Please note that I'll be modifying the trigger data in this method. So the only option is to pass the Trigger directly as a parameter.
Thank you.