You need to sign in to do that
Don't have an account?
Help required to design an Helper Class for Both Trigger and Apex
Hello Developers
I am new to the Apex Development, we have multiple triggers on a Opportunity, So i have been Given a Task to create a OpportunityHelper Class where all the Logic has to be Implemented in a Single Class, i am getting some errors where i am not able to resolve it
This is my below Trigger Logic
Below is My OpportunityTrigger
This is My OpportunityHelper
I am new to the Apex Development, we have multiple triggers on a Opportunity, So i have been Given a Task to create a OpportunityHelper Class where all the Logic has to be Implemented in a Single Class, i am getting some errors where i am not able to resolve it
This is my below Trigger Logic
trigger opportunityTrigger on Opportunity (after delete,after update,after insert,after undelete) { set<ID>QtaIds = new set<ID>(); if(trigger.isinsert || trigger.isundelete){ for(opportunity opp : trigger.new){ QtaIds.add(opp.Quota__c); } } if(trigger.isdelete){ for(opportunity opp : trigger.old){ QtaIds.add(opp.Quota__c); } } if(trigger.isupdate){ for(opportunity opp:trigger.new){ QtaIds.add(opp.Quota__c); if(trigger.oldmap.get(opp.id).Quota__c != opp.Quota__c && trigger.oldmap.get(opp.id).Quota__c != null ){ QtaIds.add(trigger.oldmap.get(opp.id).Quota__c); } } } map<id,double> amtmap = new map<id,double>(); for(aggregateresult ag : [SELECT SUM(Amount) sum,Quota__c FROM Opportunity where Quota__c in :QtaIds and ClosedDate_Checkbox__c ='True' and StageName = 'Closed Won' group by Quota__c ]){ amtmap.put((ID)ag.get('Quota__c'), double.valueof(ag.get('SUM'))); } list<Quota__c>Qtalist = new list<Quota__c>(); for(id iid : QtaIds){ Quota__c quot = new Quota__c(id=iid); if(amtmap.containskey(iid)){ quot.Inside_Sales_Roll_up__c = amtmap.get(iid); }else{ quot.Inside_Sales_Roll_up__c = 0; } Qtalist.add(quot); } if(Qtalist.size()>0){ update Qtalist; } }
Below is My OpportunityTrigger
trigger OpportunityTrigger on Opportunity (after insert,after update) { IF(Trigger.isafter && Trigger.isupdate){ OpportunityHelper.MMCountRollUpAmount(); } }
This is My OpportunityHelper
public class OpportunityHelper { public static Map<Id, Quota__c> QuotaMap =new Map<Id, Quota__c>(); public static Map<String, List<Opportunity>> OpportunityListMap = new Map<String, List<Opportunity>>(); public static set<ID>QtaIds = new set<ID>(); public static void MMCountRollUpAmount(set<id> QuotaIdSet){ set<ID>QtaIds = new set<ID>(); if(trigger.isinsert || trigger.isundelete){ for(opportunity opp : trigger.new){ QtaIds.add(opp.Quota__c); } } if(trigger.isdelete){ for(opportunity opp : trigger.old){ QtaIds.add(opp.Quota__c); } } if(trigger.isupdate){ for(opportunity opp:trigger.new){ QtaIds.add(opp.Quota__c); if(trigger.oldmap.get(opp.id).Quota__c != opp.Quota__c && trigger.oldmap.get(opp.id).Quota__c != null ){ QtaIds.add(trigger.oldmap.get(opp.id).Quota__c); } } } map<id,double> amtmap = new map<id,double>(); for(aggregateresult ag : [SELECT SUM(Amount) sum,Quota__c FROM Opportunity where Quota__c in :QtaIds and Closed_Date_Checkbox__c ='True' AND StageName = 'Closed Won' group by Quota__c ]){ amtmap.put((ID)ag.get('Quota__c'), double.valueof(ag.get('SUM'))); } list<Quota__c>Qtalist = new list<Quota__c>(); for(id iid : QtaIds){ Quota__c quot = new Quota__c(id=iid); if(amtmap.containskey(iid)){ quot.Inside_Sales_Roll_up__c = amtmap.get(iid); }else{ quot.Inside_Sales_Roll_up__c = 0; } Qtalist.add(quot); } if(Qtalist.size()>0){ update Qtalist; } } }
Please find below code. Let me know if face any errors.
Opportunity Trigger OpportunityHelper
Thanks for the Reply, Still i am Getting the same Errors
Error - Method does not exist or incorrect signature: void MMCountRollUpAmount(List<Opportunity>, List<Opportunity>) from the type OpportunityHelper
Errors
where Quota__c in :QtaIds and Closed_Date_Checkbox__c ='True'
^
ERROR at Row:1:Column:80
value of filter criterion for field 'Closed_Date_Checkbox__c' must be of type boolean and should not be enclosed in quotes
So my overall Code is
Please replace with It will work.