Method does not exist or incorrect signature: void completeMilestoneDate(List<Case>, List<Case>) from the type CompleteMilesone

  • I am not getting whats going wrong here ?

    trigger CaseTrigger on Case (before update) {
        CompleteMilesone.completeMilestoneDate(Trigger.new, Trigger.old);
    }
    

    and CompleteMilesone

    public class CompleteMilesone {
    
        public static void completeMilestoneDate(List<Case> newCases, List<Case> oldCases){
            List<Id> caseIds1 = new List<Id>();
            List<Id> caseIds2 = new List<Id>();
    
            for(Case cs : newCases){
                if(oldCases.get(cs.Id).Status == 'AAA' && newCases.get(cs.Id).Status == 'BBB'){
                    caseIds1.add(cs.Id);
                } 
                else if(oldCases.get(cs.Id).Status == 'BBB' && newCases.get(cs.Id).Status == 'CCC'){
                    caseIds2.add(cs.Id);
                }
            }
    
            if(!caseIds1.isEmpty())
                MilestoneUtils.completeMilestone(caseIds1, 'KKK1', System.now());
            else if(!caseIds2.isEmpty())
                 MilestoneUtils.completeMilestone(caseIds2, 'KKK2', System.now());
        }
    }
    

    I am getting the below errors:

    Method does not exist or incorrect signature: void completeMilestoneDate(List<Case>, List<Case>) from the type CompleteMilesone
    

    enter image description here

    I am simply formatting the below code. So that no logic is inside Case Trigger since I have almost 50 triggers in case object

    enter image description here

    One more screen shots:

    enter image description here

    Note you have a typo in your class name.

    Also, you cannot do `oldCases.get(cs.Id)` on a List. You need a `Map` for that

    Please use ***text*** to share your error messages and code. It is much more broadly accessible, and it can also be *searched*.

  • Trigger.new is List<SObject>. List<SObject> can't be passed to List<Case> parameter, because it could be not only Case, but other SObject (SObject instanceof Case == false). So change types of parameter and then cast it to List<Case>

    public static void completeMilestoneDate(List<SObject> newSobjs, List<SObject> oldSobjs){
        List<Case> newCases = (List<Case>) newSobjs;
        List<Case> oldCases = (List<Case>) oldSobjs;
        ...
    }
    

    Then according do your screenshot you didn't save CompleteMilesone class because of trying to call oldCases.get(cs.Id). Container List doesn't have get method, that accepts Id as parameter. if you want to get old Case record based on Case Id:

    Map<Id, Case> oldCasesMap =  new Map<Id, Case>(oldSobjs);
    

    But in this case, it is better to pass Trigger.oldMap as second parameter of completeMilestoneDate method.

    So your final version of code looks like:

    public class CompleteMilesone {
    
        public static void completeMilestoneDate(List<SObject> newSobjs, Map<Id,SObject> oldSobjsMap){
            List<Case> newCases = (List<Case>) newSobjs;
            Map<Id, Case> oldCasesMap = (Map<Id, Case>)oldSobjsMap;
            List<Id> caseIds1 = new List<Id>();
            List<Id> caseIds2 = new List<Id>();
    
            for(Case cs : newCases){
                Case oldCs = oldCasesMap.get(cs.Id);
                if(oldCs.Status == 'AAA' && cs.Status == 'BBB'){
                    caseIds1.add(cs.Id);
                } else if(oldCs.Status == 'BBB' && cs.Status == 'CCC'){
                    caseIds2.add(cs.Id);
                }
            }
            if(!caseIds1.isEmpty())
                MilestoneUtils.completeMilestone(caseIds1, 'KKK1', DateTime.now());
            else if(!caseIds2.isEmpty())
                 MilestoneUtils.completeMilestone(caseIds2, 'KKK2', DateTime.now());
        }
    }
    

    Final version of trigger:

    trigger CaseTrigger on Case (before update) {
        CompleteMilesone.completeMilestoneDate(Trigger.new, Trigger.oldMap);
    }
    

    According to your screenshot you weren't able to successfully save `CompleteMilesone` class. Am I wrong?

    @JavaBest that is what I am talking about. I've updated my post. It now describes your problem

    ohk. I have added screen shot which is the error now I am facing

    Thanks, Now why this is not saving ?`trigger CaseTrigger on Case (before update) { CompleteMilesone.completeMilestoneDate(Trigger.new, Trigger.old); }`

    @JavaBest and I've updated my post one more time with trigger :)

License under CC-BY-SA with attribution


Content dated before 7/24/2021 11:53 AM