You need to sign in to do that
Don't have an account?
Need Help to to write Test Class for the Apex class
Hello Developers
i am trying to design a Test class for the Apex class but i am not able to do the code coverage of the following apex class, can anyone please help
i am trying to design a Test class for the Apex class but i am not able to do the code coverage of the following apex class, can anyone please help
public class FutureHandler { @future public static void updaterecs(Map<String,Id> oldManagerQuotaMap1){ Map<Id,Quota__c> oldMapQuota = new Map<Id,Quota__c>(); if(null != oldManagerQuotaMap1 && oldManagerQuotaMap1.size() > 0){ for (aggregateResult result: [Select Manager_Quota__c, Sum(Inside_Sales_Roll_Up__c) FROM Quota__c WHERE Manager_Quota__c IN: oldManagerQuotaMap1.values() GROUP BY Manager_Quota__c]) { system.debug('result'+result) ; oldMapQuota.put((Id)result.get('Manager_Quota__c'),new Quota__c(Id=(Id)result.get('Manager_Quota__c'),Actual_Amount__c =(Decimal)result.get('expr0'))); } for(Id qId : oldManagerQuotaMap1.values()){ if(!oldMapQuota.containskey(qId)){ oldMapQuota.put(qId, new Quota__c(Id = qId,Actual_Amount__c = 0.0)); } } if(null != oldMapQuota && oldMapQuota.size() > 0){ update oldMapQuota.values(); } } } public static void sendOppsForApproval(List<Opportunity> opps){ List<Opportunity> oppsToBeSentForApproval = new List<Opportunity>(); String monthYear = System.now().format('MMMM-yyyy'); String month = monthYear.split('-')[0]; String year = monthYear.split('-')[1]; Date nextMonthStart = System.today().toStartOfMonth().addMonths(1).toStartOfMonth(); List<Aggregate_Approval__c> appr = [Select Id from Aggregate_Approval__c where Month__c=:month And Year__c=:year]; Id approvalId; if(appr.size()>0){ approvalId = appr[0].Id; for(Opportunity opp : opps){ opp.Aggregate_Approval__c = approvalId; opp.Status__c = 'In Approval'; oppsToBeSentForApproval.add(opp); } update oppsToBeSentForApproval; // List<Approval.LockResult> li = Approval.lock(opps); Approval.ProcessSubmitRequest oppAggregateApproval = new Approval.ProcessSubmitRequest(); oppAggregateApproval.setComments('Submitting opportunities for Approval for '+System.now().format('MMMM-yyyy')); oppAggregateApproval.setObjectId(approvalId); Approval.ProcessResult approvalResult = Approval.process(oppAggregateApproval); } } }My Test Class
@isTest public class FutureHandlerTestclass { static testmethod void Futuretest(){ List<Quota__c> Ftur = new list <Quota__c>(); Quota__c FF = new Quota__c(); FF.Name='Julian'; FF.Assigned_To__c = userinfo.getUserId(); FF.Month__c='March'; FF.Quater__c='Q1'; FF.Quater_Year__c = '2020'; FF.Actual_Amount__c = 100; FF.Unique_Identifier_Per_Quater_Per_User__c = 'Hello'; Ftur.add(FF); insert FF; Quota__c FF1 = new Quota__c(); FF1.Name='rahul'; FF1.Assigned_To__c = userinfo.getUserId(); FF1.Month__c='October'; FF1.Quater__c='Q4'; FF1.Quater_Year__c = '2030'; FF.Actual_Amount__c = 200; FF1.Unique_Identifier_Per_Quater_Per_User__c = 'Helloworld'; Ftur.add(FF1); insert FF1; Account testAcct = new Account (Name = 'My Test Account'); insert testAcct; User u = [Select id,name from user where isactive=true Limit 1]; List<Opportunity> Oppps = new list <Opportunity>(); Opportunity oop = new Opportunity(); oop.Name = 'Test1'; oop.AccountId = testAcct.ID; oop.StageName = 'Demo'; oop.CloseDate = system.today(); oop.Billing_To_Be_Initiated__c = 'Yes'; oop.LeadSource = 'Customer'; oop.Country__c = 'India'; Oppps.add(oop); insert oop; } }
Hi Nilima,
If it is just a class(Not called from trigger) ,Then First you need to insert class mathod at the End of method. Otherwise it will not call class. I have updated your test class. Hope it will help you.
its throwing an error in the line 29, says DML requires SObject or SObject list type: Map<String,Id>, how do i resolve it