2

I use a framework of a trigger factory to set up all my triggers and handlers of those triggers. Earlier I got some great advice on how to separate my concerns better for the handler.

I use this block for afterUpdate:

public override void afterUpdate(Map<Id, SObject> oldMapGeneric, Map<Id, SObject> newMapGeneric){
    Map<Id, Revenue_Pipeline__c> oldMap = (Map<Id, Revenue_Pipeline__c>) oldMapGeneric;
    Map<Id, Revenue_Pipeline__c> newMap = (Map<Id, Revenue_Pipeline__c>) newMapGeneric;
    /*AFTER UPDATE METHODS START*/
    if(!isRecursive)
    {
        isRecursive = true;
        List<Revenue_Pipeline__c> filtered = Revenue_PipelineTriggerHandler.needsNewSchedule(newMap, oldMap);
        deleteSchedule(filtered);
        createRevSchedule(filtered); 
    }
    /*AFTER UPDATE METHODS END*/
}

This then references my query method:

public void needsNewSchedule(Map<Id, Revenue_Pipeline__c> newMap, Map<Id, Revenue_Pipeline__c> oldMap)
{
    List<Revenue_Pipeline__c> revPipeline = new List<Revenue_Pipeline__c>();
    // Check if the fields changed

    for(Revenue_Pipeline__c revPipe : newMap.values())
    {
        if(
            revPipe.Product_Start_Date__c       != oldMap.get(revPipe.Id).Product_Start_Date__c ||
            revPipe.Product_End_Date__c         != oldMap.get(revPipe.Id).Product_End_Date__c ||
            revPipe.Product_Price__c            != oldMap.get(revPipe.Id).Product_Price__c ||
            revPipe.Weighted_Product_Price__c   != oldMap.get(revPipe.Id).Weighted_Product_Price__c)
            {
                revPipeline.add(revPipe.Id);
            }
    }
}

My problem is I get an error on the line:

List<Revenue_Pipeline__c> filtered = SL_Revenue_PipelineTriggerHandler.needsNewSchedule(newMap, oldMap);

With

Method does not exist or incorrect signature: Revenue_PipelineTriggerHandler.needsNewSchedule(Map, Map)

I'm accepting the newmap and oldMap in the method why does it not compile?

3

Your method needs to be static if you want to call it as you do now.

Incorrect

public void staticMethod(...)

MyClass.staticMethod(...)

Correct

public static void staticMethod(...)

MyClass.staticMethod(...)

Or you can leave the method as is and call it from an instance:

Incorrect

public void instanceMethod(...)

MyClass.instanceMethod(...)

Correct

public void instanceMethod(...)

new MyClass().instanceMethod(...)

In this case, though, you don't have any stateful information so you should go with the first approach.

  • So I updated the line: public static void needsNewSchedule(Map<Id, Revenue_Pipeline__c> newMap, Map<Id, Revenue_Pipeline__c> oldMap) When I compile I getthe error >Illegal assignment from void to List<Revenue_Pipeline__c> – Dan Wooding Jan 18 '17 at 18:51
  • @Dan Change the return type from void to List<Revenue_Pipeline__c>. – Adrian Larson Jan 18 '17 at 19:13
  • This one little piece has me messed up for an hour, – Dan Wooding Jan 18 '17 at 20:00

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.