You need to sign in to do that
Don't have an account?
Dolgoldy
instant Help to write test class
HI all,
I amm beginner in apex so please help me to write test class for below handler class
I amm beginner in apex so please help me to write test class for below handler class
*********Write test class for below class*********** public class TestHelper { public static Integer TestCounter1 = 0; public static Integer TestCounter2 = 0; public void DataTEst(List<TEst__c> objtest) { Set<Id> logicIds = new Set<Id>(); for(TEst__c te : objtes) { logicIds.add(te.TEstLogic__c); } AggregateResult [] TestAgg = [Select TEstLogic__c, MIN(Date__c) Earliest, MAX(Date__c) Latest from TEst__c Where TEstLogic__c IN :logicIds Group BY TEstLogic__c]; Map<Id, TEstLogic__c> logicMap = new Map<Id, TEstLogic__c>([Select Id, Logic__c, Date__c from TEstLogic__c Where ID IN :logicIds]); List<TEstLogic__c> logicToUpdate = new List<TEstLogic__c>(); Set<Id> tdblogicIDs = new Set<Id>(); for(Test__c M : [Select TEstLogic__c from test__c Where TEstLogic__c__c IN :logicIds and Date__c = null]) { tdblogicIDs.add(M.Epix_Date_Math_Logic__c); } for (AggregateResult ar : mathAggregate) { String logicId = (String)ar.get('TEstLogic__c'); if(logicMap.containsKey(logicId)){ TEstLogic__c logic = logicMap.get(logicId); if(logic.Logic__c == 'Earliest Of' || logic.Logic__c == 'Equals') { if(tdblogicIDs.contains(logicId)){ logic.Date__c = null; }else { logic.Date__c = (Date)ar.get('Earliest'); } }else if(logic.Logic__c == 'Latest Of') logic.Date__c = (Date)ar.get('Latest'); logicToUpdate.add(logic); } } update logicToUpdate; } public void updateDateMathLogic(List<TEstLogic__c> dateLogicList) { Map<Id, String> testField1 = new Map<Id, String>(); Map<Id, String> testField2 = new Map<Id, String>(); Map<Id, String> testField3 = new Map<Id, String>(); Map<Id, Date> testField1 = new Map<Id, Date>(); Map<Id, Date> testField2 = new Map<Id, Date>(); Map<Id, Date> testField3 = new Map<Id, Date>(); Set<String> testField1 = new Set<String>(); Set<String> testField2 = new Set<String>(); Set<String> testField3 = new Set<String>(); List<testField1__c> testField1 = new List<test1__c>(); List<testField2__c> testField2 = new List<test2__c>(); List<Opportunity> oppList = new List<Opportunity>(); for(TEstLogic__c logic : LogicLst) { if(logic.test!=null) { testField1__c.put(logic.Destination_testField1__c, logic.Api__c); testField1__c.put(logic.Destination_Milestone__c, logic.Date__c); testField1__c.add(logic.Api__c); } if(logic.Destination_testField2__c!=null) { pickupIdvField.put(logic.Destination_testField2__c, logic.Api__c); pickupIdvDate.put(logic.Destination_testField2__c, logic.Date__c); pickupFields.add(logic.Api__c); } if(logic.Opportunity__c!=null) { oppIdvField.put(logic.Opportunity__c, logic.Api__c); oppIdvDate.put(logic.Opportunity__c, logic.Date__c); oppFields.add(logic.Api__c); } } if(testField1.size() > 0){ List<String> fields = new List<String>(); fields.addAll(testField1__c>); String cols = string.join(fields,','); Set<Id> keys = testField1__c>.keyset(); String query = 'Select Id, ' + cols + ' From testField1__c> Where Id IN : keys'; testField1List = Database.query(query); } if( testField2.size() > 0){ List<String> fields = new List<String>(); fields.addAll( testField2); String cols = string.join(fields,','); Set<Id> keys = testField2.keyset(); String query = 'Select Id, ' + cols + ' From testField2 Where Id IN : keys'; testField1 = Database.query(query); } if(testField3.size() > 0){ List<String> fields = new List<String>(); fields.addAll(testField1); String cols = string.join(fields,','); Set<Id> keys = testField3.keyset(); String query = 'Select Id, ' + cols + ' From Opportunity Where Id IN : keys'; oppList = Database.query(query); } for( testField1 m : testField1list){ System.debug('#6. Calculated Date -> ' + testField1.get(m.Id)); m.put(testField1.get(m.Id),testField1.get(m.Id)); } for( testField2 p : testFieldlist){ p.put(testField2.get(p.Id), testField2.get(p.Id)); } for( Opportunity o : oppList){ o.put(oppIdvField.get(o.Id), oppIdvDate.get(o.Id)); } update testField1; update testField2; update oppList; } }
Check this:
https://salesforce.stackexchange.com/questions/244788/how-do-i-write-an-apex-unit-test
https://salesforce.stackexchange.com/questions/244794/how-do-i-increase-my-code-coverage-or-why-cant-i-cover-these-lines
If you face any specific issues while writing do post that here.
Thanks!
I am having issue to solve test class for above class can anyone help me to sort out this plz