You need to sign in to do that
Don't have an account?

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.
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.
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.
Thanks,
All Answers
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.
If this solution helps, Please mark it as best answer.
Thanks,
Can I know what errors are still there. in my org with the above code i dont see any errors.
Thanks,
And in Tigger Method Doesn't exist
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.
Thanks,