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
Dhruv NirgudeDhruv Nirgude 

Method And Variable doesn't exist

Hey, In Trigger and TriggerHandlerClass I've some errors regarding "Method Doesn't exist" as well as "Variable Doesn't exist". In Below i am going to show my code as well as all those error points which i found in my Problem tab.
Trigger -
trigger OpportunityTrigger on Opportunity (after insert, after update, after delete){
    if (trigger.isAfter){
        if(Trigger.isInsert){
         OppoTriggerHandler.onAfterInsert(Trigger.New);
        }else if(Trigger.isUpdate){
         OppoTriggerHandler.onAfterUpdate(Trigger.New, Trigger.oldMap);
        }else if(Trigger.isDelete){
         OppoTriggerHandler.onAfterDelete(Trigger.Old);
        }    
    }
}

TriggerHandlerClass-
public class OppoTriggerHandler {
    public static void onAfterInsert(List<opportunity> newList){ 
    Set<Id> accIds = new  Set<Id>();
    List<Account> accToBeUpdated= new List<Account>();
     
       for(Opportunity opp : newList){
           if(opp.AccountId != null){
           accIds.add(opp.AccountId);    
        }      
    }    
 accToBeUpdated = calculateAnnualRevenue(accIds);
        if(!accToBeUpdated.isEmpty()){
       update accToBeUpdated;
        }    
    }
    public static void onAfterUpdate(List<Opportunity> newList, Map<Id,Opportunity> oldMap){
    Set<Id> accIds = new Set<Id>();
    List<Account> accToBeUpdated = new List<Account>();
        
        for(Opportunity opp : newList){
            if(opp.AccountId != null && opp.Amount != oldMap.get(opp.Id).Amount){
             accIds.add(opp.AccountId);     
            }   
        }
  accToBeUpdated = calculateAnnualRevenue(accIds);
 
        if(!accToBeUpdated.isEmpty()){ 
         update accToBeUpdated;
        }
    }
    public static void OnAfterDelete (List<Opportunity> oldList){
    Set<Id> accIds = new Set<Id>();
   List<Account> accToBeUpdated = new List<Account>();
        
        for(Opportunity opp : oldList){
            if(opp.AccountId != null){
             accIds.add(opp.AccountId);      
            }     
        }      
  accToBeUpdated = calculateAnnualRevenue(accIds);
   
        if(!accToBeUpdated.isEmpty()){
        update accToBeUpdated;
        }      
    }     
    public static List<Account> calculationAnnualRevenue(Set<Id> accIds){
    List<Account> accToBeUpdated = new List<Account>(); 
   Map<Id, Decimal> accIdToAnnualRevenue = new Map<Id, Decimal>();
   
        for(Opportunity opp : [Select Id, Amount From Opportunity Where AccountId IN : accIds]){
      Decimal total = 0;
            if(accIdToAnnualRevenue.containsKey(opp.AccountId)){
          total = accIdAnnualRevenue.get(opp.AccountId);
            }
            if(opp.Amount != null){
          total = total +opp.Amount;
            }         
     accIdToAnnualRevenue.put(opp.AccountId,total);
        }
        if(!accIdAnnualRevenue.isEmpty()){
            for(Id i : accIdToAnnualRevenue.keySet()){
          Account acc = new Account();
          acc.Id = i;
         acc.AnnualRevenue = accIdToAnnualRevenue.get(i);       
        accToBeUpdated.add(acc);   
            }       
        }   
    return accToBeUpdated;    
    }   
}

Error Points
1 Method does not exist or incorrect signature: void calculateAnnualRevenue(Set<Id>) from the type OppoTriggerHandler.

2 Variable does not exist: accIdAnnualRevenue.

3 Method does not exist or incorrect signature: void onAfterInsert(List<Opportunity>) from the type OppoTriggerHandler.
Best Answer chosen by Dhruv Nirgude
Sai PraveenSai Praveen (Salesforce Developers) 
Hi Dhruv,

With the changes i have given above that error also should be resolved. I have saved the class with out any errors and thus trigger got saved.
 
public class OppoTriggerHandler {
    public static void onAfterInsert(List<opportunity> newList){ 
    Set<Id> accIds = new  Set<Id>();
    List<Account> accToBeUpdated= new List<Account>();
     
       for(Opportunity opp : newList){
           if(opp.AccountId != null){
           accIds.add(opp.AccountId);    
        }      
    }    
 accToBeUpdated = calculateAnnualRevenue(accIds);
        if(!accToBeUpdated.isEmpty()){

            update accToBeUpdated;
        }    
    }
    public static void onAfterUpdate(List<Opportunity> newList, Map<Id,Opportunity> oldMap){
    Set<Id> accIds = new Set<Id>();
    List<Account> accToBeUpdated = new List<Account>();
        
        for(Opportunity opp : newList){
            if(opp.AccountId != null && opp.Amount != oldMap.get(opp.Id).Amount){
             accIds.add(opp.AccountId);     
            }   
        }
  accToBeUpdated = calculateAnnualRevenue(accIds);
 
        if(!accToBeUpdated.isEmpty()){ 
         update accToBeUpdated;
        }
    }
    public static void OnAfterDelete (List<Opportunity> oldList){
    Set<Id> accIds = new Set<Id>();
   List<Account> accToBeUpdated = new List<Account>();
        
        for(Opportunity opp : oldList){
            if(opp.AccountId != null){
             accIds.add(opp.AccountId);      
            }     
        }      
  accToBeUpdated = calculateAnnualRevenue(accIds);
   
        if(!accToBeUpdated.isEmpty()){
        update accToBeUpdated;
        }      
    }     
    public static List<Account> calculateAnnualRevenue(Set<Id> accIds){
    List<Account> accToBeUpdated = new List<Account>(); 
   Map<Id, Decimal> accIdToAnnualRevenue = new Map<Id, Decimal>();
   
        for(Opportunity opp : [Select Id, Amount From Opportunity Where AccountId IN : accIds]){
      Decimal total = 0;
            if(accIdToAnnualRevenue.containsKey(opp.AccountId)){
          total = accIdToAnnualRevenue.get(opp.AccountId);
            }
            if(opp.Amount != null){
          total = total +opp.Amount;
            }         
     accIdToAnnualRevenue.put(opp.AccountId,total);
        }
        if(!accIdToAnnualRevenue.isEmpty()){
            for(Id i : accIdToAnnualRevenue.keySet()){
          Account acc = new Account();
          acc.Id = i;
         acc.AnnualRevenue = accIdToAnnualRevenue.get(i);       
        accToBeUpdated.add(acc);   
            }       
        }   
    return accToBeUpdated;    
    }   
}

Thanks,
​​​​​​​

All Answers

Sai PraveenSai Praveen (Salesforce Developers) 
Hi Dhruv,

Can you update the ape class as below. There is some errors in the method names and that caused the issues.

Save the apex class and try to save the trigger.
public class OppoTriggerHandler {
    public static void onAfterInsert(List<opportunity> newList){ 
    Set<Id> accIds = new  Set<Id>();
    List<Account> accToBeUpdated= new List<Account>();
     
       for(Opportunity opp : newList){
           if(opp.AccountId != null){
           accIds.add(opp.AccountId);    
        }      
    }    
 accToBeUpdated = calculateAnnualRevenue(accIds);
        if(!accToBeUpdated.isEmpty()){
       update accToBeUpdated;
        }    
    }
    public static void onAfterUpdate(List<Opportunity> newList, Map<Id,Opportunity> oldMap){
    Set<Id> accIds = new Set<Id>();
    List<Account> accToBeUpdated = new List<Account>();
        
        for(Opportunity opp : newList){
            if(opp.AccountId != null && opp.Amount != oldMap.get(opp.Id).Amount){
             accIds.add(opp.AccountId);     
            }   
        }
  accToBeUpdated = calculateAnnualRevenue(accIds);
 
        if(!accToBeUpdated.isEmpty()){ 
         update accToBeUpdated;
        }
    }
    public static void OnAfterDelete (List<Opportunity> oldList){
    Set<Id> accIds = new Set<Id>();
   List<Account> accToBeUpdated = new List<Account>();
        
        for(Opportunity opp : oldList){
            if(opp.AccountId != null){
             accIds.add(opp.AccountId);      
            }     
        }      
  accToBeUpdated = calculateAnnualRevenue(accIds);
   
        if(!accToBeUpdated.isEmpty()){
        update accToBeUpdated;
        }      
    }     
    public static List<Account> calculateAnnualRevenue(Set<Id> accIds){
    List<Account> accToBeUpdated = new List<Account>(); 
   Map<Id, Decimal> accIdToAnnualRevenue = new Map<Id, Decimal>();
   
        for(Opportunity opp : [Select Id, Amount From Opportunity Where AccountId IN : accIds]){
      Decimal total = 0;
            if(accIdToAnnualRevenue.containsKey(opp.AccountId)){
          total = accIdToAnnualRevenue.get(opp.AccountId);
            }
            if(opp.Amount != null){
          total = total +opp.Amount;
            }         
     accIdToAnnualRevenue.put(opp.AccountId,total);
        }
        if(!accIdToAnnualRevenue.isEmpty()){
            for(Id i : accIdToAnnualRevenue.keySet()){
          Account acc = new Account();
          acc.Id = i;
         acc.AnnualRevenue = accIdToAnnualRevenue.get(i);       
        accToBeUpdated.add(acc);   
            }       
        }   
    return accToBeUpdated;    
    }   
}

If this solution helps, Please mark it as best answer.

Thanks,
 
Dhruv NirgudeDhruv Nirgude
Hey Sai Praveen, with the help of your class i removed some errors but still in my Class and Trigger i have some errors please help me to remove remainig errors. 
Sai PraveenSai Praveen (Salesforce Developers) 
Hi Dhruv,

Can I know what errors are still there. in my org with the above code i dont see any errors.

Thanks,
 
Dhruv NirgudeDhruv Nirgude
accToBeUpdated = calculateAnnualRevenue(accIds);

And in Tigger Method Doesn't exist
Sai PraveenSai Praveen (Salesforce Developers) 
Hi Dhruv,

With the changes i have given above that error also should be resolved. I have saved the class with out any errors and thus trigger got saved.
 
public class OppoTriggerHandler {
    public static void onAfterInsert(List<opportunity> newList){ 
    Set<Id> accIds = new  Set<Id>();
    List<Account> accToBeUpdated= new List<Account>();
     
       for(Opportunity opp : newList){
           if(opp.AccountId != null){
           accIds.add(opp.AccountId);    
        }      
    }    
 accToBeUpdated = calculateAnnualRevenue(accIds);
        if(!accToBeUpdated.isEmpty()){

            update accToBeUpdated;
        }    
    }
    public static void onAfterUpdate(List<Opportunity> newList, Map<Id,Opportunity> oldMap){
    Set<Id> accIds = new Set<Id>();
    List<Account> accToBeUpdated = new List<Account>();
        
        for(Opportunity opp : newList){
            if(opp.AccountId != null && opp.Amount != oldMap.get(opp.Id).Amount){
             accIds.add(opp.AccountId);     
            }   
        }
  accToBeUpdated = calculateAnnualRevenue(accIds);
 
        if(!accToBeUpdated.isEmpty()){ 
         update accToBeUpdated;
        }
    }
    public static void OnAfterDelete (List<Opportunity> oldList){
    Set<Id> accIds = new Set<Id>();
   List<Account> accToBeUpdated = new List<Account>();
        
        for(Opportunity opp : oldList){
            if(opp.AccountId != null){
             accIds.add(opp.AccountId);      
            }     
        }      
  accToBeUpdated = calculateAnnualRevenue(accIds);
   
        if(!accToBeUpdated.isEmpty()){
        update accToBeUpdated;
        }      
    }     
    public static List<Account> calculateAnnualRevenue(Set<Id> accIds){
    List<Account> accToBeUpdated = new List<Account>(); 
   Map<Id, Decimal> accIdToAnnualRevenue = new Map<Id, Decimal>();
   
        for(Opportunity opp : [Select Id, Amount From Opportunity Where AccountId IN : accIds]){
      Decimal total = 0;
            if(accIdToAnnualRevenue.containsKey(opp.AccountId)){
          total = accIdToAnnualRevenue.get(opp.AccountId);
            }
            if(opp.Amount != null){
          total = total +opp.Amount;
            }         
     accIdToAnnualRevenue.put(opp.AccountId,total);
        }
        if(!accIdToAnnualRevenue.isEmpty()){
            for(Id i : accIdToAnnualRevenue.keySet()){
          Account acc = new Account();
          acc.Id = i;
         acc.AnnualRevenue = accIdToAnnualRevenue.get(i);       
        accToBeUpdated.add(acc);   
            }       
        }   
    return accToBeUpdated;    
    }   
}

Thanks,
​​​​​​​
This was selected as the best answer
Dhruv NirgudeDhruv Nirgude
Thanks Sai.