You need to sign in to do that
Don't have an account?
Saru Vadlamudi
How to cover catch exception in test class
Can any one help me out that how to cover the code coverage for below catch excpetion in test class.
I dont have permission to change Apex Controller so it has to do something in test class itself.
catch(Exception e) {
new ApexPages.Message(ApexPages.Severity.Error,'Easy Button Config Custom Setting doesn\'t exist!');
}
I dont have permission to change Apex Controller so it has to do something in test class itself.
catch(Exception e) {
new ApexPages.Message(ApexPages.Severity.Error,'Easy Button Config Custom Setting doesn\'t exist!');
}
try this in your test class.
try
{
//perform actions like insert,update,delete...etc that causes your exception to occur
system.assert(false);
}
Catch(exception e)
{
}
Boolean faultAnalysisFlag = false;
try{
if(!String.IsEmpty(stockingRecordId) && !String.isEmpty(mmId)){
List<ICS_WR_Customer_Warranty_Config_Matrix__c> faultMatrix = [SELECT id,Name,RecordTypeId FROM ICS_WR_Customer_Warranty_Config_Matrix__c WHERE ICS_WR_Stocking__c=:stockingRecordId AND ICS_WR_MMID__r.Name=:mmId AND RecordTypeId=:Label.ICS_WR_Fault_Analysis_RT_ID];
System.debug('faultMatrix ='+faultMatrix );
if(faultMatrix!=null && faultMatrix.size()>0)
faultAnalysisFlag = true;
}
}catch(Exception e){
System.Debug(e.getMessage());
ApexPages.addMessages(e);
String strInvocationID ='ICS_WR_Warranty_CreateExtension'+UserInfo.getUserId() + '_' + system.now().formatGmt('yyyyMMddkkmmssSS')
+ '_' + String.valueOf((Math.random() * 10).round()).leftpad(3,'0');
Core_Log_Entry.logEntryWithException(strInvocationID,System.Label.ICS_WR_logging_Scope,'ICS_WR_Warranty_CreateExtension__checkFaultAnalysis','Error',e.getMessage(),'',e);
}
return faultAnalysisFlag;
}