You need to sign in to do that
Don't have an account?
Raffus
Written a test class but few Lines are not covered?
I have written a test class but a few lines are not covered. I do not understand how to cover it. Please help!!!
These lines are not covered by the above code.
@AuraEnabled public static demoWrapper getData(String Club){ String userId= User.getLoggedInUserId(); List<User> userRec = [Select Id, Name,accountId,ContactId,ViewActivity__c from User where Id =: userId]; List<BTS__c> BTSList = new List<BTS__c>(); List<Services__c> serviceList = new List<Services__c>(); Integer percentage = 0; demoWrapper wrapperobj = new demoWrapper(); String accountIdstr = userRec[0].accountId; if(accountIdstr <> null && accountIdstr != ''){ serviceList = [Select id, Account__c,Account__r.RecordType.Name,Account__r.CreatedDate,Broker_of_Record__c, Broker_of_Record__r.Club__c from Services__c where Broker_of_Record__c =: accountIdstr AND Account__r.RecordType.Name = 'Group']; BTSList = [Select id, name, RPoints__c,Milestone_Date__c,RecordType.Name,Trip_Status_Eligibility__r.Pinnacle_Target_Points__c,Trip_Status_Eligibility__r.RecordType.Name, Trip_Status_Eligibility__r.Premier_Target_Points__c,Trip_Status_Eligibility__r.Preferred_Target_Points__c, Trip_Status_Eligibility__r.Active__c,Trip_Status_Eligibility__r.Start_Date__c, Trip_Status_Eligibility__r.End_Date__c FROM BTS__c WHERE Trip_Status_Eligibility__r.Active__c = true AND Account__c =: accountIdstr AND RecordType.Name = 'Broker Reward' limit 1]; } if(!BTSList.isEmpty() && BTSList[0].RecordType.Name == 'Broker Reward') { Integer additionaldays = Integer.valueOf(Label.AFocus_NewGrpNumOfDaysForRewardCal); Date grpcreatedStartDate = BTSList[0].Trip_Status_Eligibility__r.Start_Date__c - additionaldays; Date grpcreatedEndDate = BTSList[0].Trip_Status_Eligibility__r.End_Date__c + additionaldays; Map<Id,Set<Id>> grpAccMap = new Map<Id,Set<Id>>(); if(!serviceList.isEmpty()){ for(Services__c servRec : serviceList ){ if((servRec.Account__r.CreatedDate >= grpcreatedStartDate) && (servRec.Account__r.CreatedDate <= grpcreatedEndDate)) { if(!grpAccMap.containsKey(servRec.Broker_of_Record__c)){ grpAccMap.put(servRec.Broker_of_Record__c, new Set<Id>()); } grpAccMap.get(servRec.Broker_of_Record__c).add(servRec.Account__c); } } } system.debug('serviceList =' + serviceList); system.debug('grpAccMap =' + grpAccMap); if(grpAccMap != null && ! grpAccMap.isEmpty()){ if(grpAccMap.get(accountIdstr) != null){ if(grpAccMap.get(accountIdstr).size() >= 2){ wrapperobj.GrpAccts = 2; } else if(grpAccMap.get(accountIdstr).size() ==1){ wrapperobj.GrpAccts = 1; } } } else if(grpAccMap == null || grpAccMap.isEmpty()){ wrapperobj.GrpAccts = 0; } if(Club == 'premierClub' && BTSList[0].RPoints__c != null && BTSList[0].Trip_Status_Eligibility__r.Premier_Target_Points__c != null && BTSList[0].Trip_Status_Eligibility__c!=null){ percentage = Integer.valueOf(((BTSList[0].RPoints__c)*100) / (BTSList[0].Trip_Status_Eligibility__r.Premier_Target_Points__c)); wrapperobj.tPoints = Integer.valueOf(BTSList[0].Trip_Status_Eligibility__r.Premier_Target_Points__c); } else if(Club == 'preferredClub' && BTSList[0].RPoints__c != null && BTSList[0].Trip_Status_Eligibility__r.Preferred_Target_Points__c != null && BTSList[0].Trip_Status_Eligibility__c!=null){ percentage = Integer.valueOf(((BTSList[0].RPoints__c)*100) / (BTSList[0].Trip_Status_Eligibility__r.Preferred_Target_Points__c)); wrapperobj.tPoints = Integer.valueOf(BTSList[0].Trip_Status_Eligibility__r.Preferred_Target_Points__c); } wrapperobj.rPoints = Integer.valueOf(BTSList[0].RPoints__c); wrapperobj.hasActive = BTSList[0].Trip_Status_Eligibility__r.Active__c; } wrapperobj.ViewRewards = userRec[0].ViewActivity__c; wrapperobj.perRewards= percentage; system.debug('wrapperobj' +wrapperobj); return wrapperobj; } public class demoWrapper { @AuraEnabled public Integer tPoints{get;set;} @AuraEnabled public Integer rPoints{get;set;} @AuraEnabled public Integer perRewards{get;set;} @AuraEnabled public Boolean ViewRewards{get;set;} @AuraEnabled public Boolean hasActive{get;set;} @AuraEnabled public Integer GrpAccts{get;set;} }
These lines are not covered by the above code.
for(Services__c servRec : serviceList ){ if((servRec.Account__r.CreatedDate >= grpcreatedStartDate) && (servRec.Account__r.CreatedDate <= grpcreatedEndDate)) { if(!grpAccMap.containsKey(servRec.Broker_of_Record__c)){ grpAccMap.put(servRec.Broker_of_Record__c, new Set<Id>()); } grpAccMap.get(servRec.Broker_of_Record__c).add(servRec.Account__c); } }
if(grpAccMap != null && ! grpAccMap.isEmpty()){ if(grpAccMap.get(accountIdstr) != null){ if(grpAccMap.get(accountIdstr).size() >= 2){ wrapperobj.GrpAccts = 2; } else if(grpAccMap.get(accountIdstr).size() ==1){ wrapperobj.GrpAccts = 1; } } }
Can you share the test class which you have written so I can check and let you know what to change in it.
Thanks,
Can you confirm what do we have in AFocus_NewGrpNumOfDaysForRewardCal label .
Thanks,
I dont think you are getting the Accountid in the test class for the below line.
Can you confirm in debug logs if you are getting it or not and the record type should be 'Group'.
Thanks,
After adding record type still not working -
Id recordTypeAccount = Schema.SObjectType.Account.getRecordTypeInfosByName().get('Group').getRecordTypeId();
Account accUpdate = [Select Id, ParentId from Account where Id=: portalContact.Accountid and RecordTypeId =: recordTypeAccount];
Error - System.QueryException: List has no rows for assignment to SObject
Which means that you need to create the record Account which satifies the condition in test class.
Thanks,