You need to sign in to do that
Don't have an account?
nagas
coverage for DataBase.Error
hi,
I am trying to write a test class for a class named SystemUtility in which i couldnt make the coverage go more than 62%
Class code:
global class SystemUtility { public static String getErrorString(List<Database.Saveresult> saveResult){ String error=''; for(Database.Saveresult result : saveResult){ if(!result.isSuccess()){ for(Database.Error err : result.getErrors()){ error+=err; } return error; } } return error; } }
Test class:
@isTest private class SystemUtilityTest { static testMethod void myUnitTest() { Territory ter = new Territory(name = 'testterr1',Geo__c = 'AMS' ,Super_Org__c ='CA_SO', Organization__c = 'CANADA_FIELD', Region__c = 'CANADA', Area__c = 'CA_ENTERPRISE_1', District_Team__c = 'CA_DISTRICT_1', Sector_Vertical__c = 'HEALTHCARE', Segment__c = 'COMMERCIAL', Territory_Type__c = 'HEALTHCARE_ISV_TERRITORY', Active_Flag__c = 'Active', Fiscal_Year__c = 'Old', Open_Territory__c = false , Effective_Start_Date__c = System.today(), Effective_End_Date__c = null, Business_Reason__c = 'Test Purpose', Quota_Bearing__c = true , OIC_Territory_Flag__c = false ); List<Territory> terrs = new List<Territory>(); terrs.add(ter); Profile prof =[select id from profile where name = 'Master GCM Administrator']; User us = [select id,profileId from user where profileId =:prof.Id and IsActive = true LIMIT 1]; // Run as Master GCM Administrator System.runAs(us){ // Start the Test Test.startTest(); List<Database.Saveresult> res = Database.Insert(terrs); String errorStr = SystemUtility.getErrorString(res); //Stop the Test Test.stoptest(); } } }
I am facing the coverage issue with the database.error part of the test class. Can anybody let me know how can i make it covered.
Hi,
Did you get any solution for this ? I am facing the same problem.