You need to sign in to do that
Don't have an account?
Kunal Purohit 4
How to write test class for below Handler?
Hello Folks, I am trying to write test class for below code. Its not moving beyond 45%. Can you please help me to achieve the same?
public class SumAmountOppHandler { List<Account> accList=new List<Account>(); Set<Id> setAccIds = new Set<Id>(); public void afterinsert(List<Opportunity> newoppylist){ for(Opportunity con : newoppylist){ if(con.AccountId != null && con.Amount>10000.00){ setAccIds.add(con.AccountId); updateamount(setAccIds) ; } } } public void afterupdate(List<Opportunity> newoppylist, Map<Id,Opportunity> mapoppy){ for(Opportunity con : newoppylist){ if(con.AccountId!=mapoppy.get(con.Id).AccountId && con.Amount>10000.00){ setAccIds.add(con.AccountId); setAccIds.add(mapoppy.get(con.Id).AccountId); updateamount(setAccIds) ; } } } public void afterdelete(List<Opportunity> oldoppylist){ for(Opportunity con : oldoppylist){ if(con.AccountId != null && con.Amount>10000.00){ setAccIds.add(con.AccountId); updateamount(setAccIds) ; } } } public void updateamount(set<id> accids){ for(Account acc :[Select id,Total_Opty_Amount__c ,(Select Amount from Opportunities where Amount>10000.00) from Account where Id in : accids]){ acc.Total_Opty_Amount__c = acc.Opportunities.size(); acclist.add(acc); } if(acclist.size()>0){ update accList; } } }
The test class can be as below.
It will cover both Trigger and handler 100%.
Let me know if you face any issues.
If this solution helps, Please mark it as best answer.
Thanks,