1

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.

1

Try below, 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,'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, string ta ) {

            // Insert
            if( ta == 'beforeInsert' ) {

            }

            // Update
            if( ta == 'beforeUpdate' ) {

            }

        }

    }
2
  • 1
    Holy effing cow! It was that goddamned enum all this while. Wasted greater part of the day on something as simple as this. Thanks a tonne @snehakem. Would you happen to know why the enum fails? The examples stated here: gokubi.com/archives/… seem to indicate that the enums work perfectly. – miCRoSCoPiC_eaRthLinG May 25 '15 at 6:57
  • 1
    Your welcome. i am not sure if the code works that way. In this case if i had to use enum then i would have declared it in a utility class as static and used it in both trigger as well as class instead of declaring it twice. – snehakem May 25 '15 at 8:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.