You need to sign in to do that
Don't have an account?
satish marisetty 10
how can i cover exception of this method
how can i conver exception catch block of this method in my test class
public static Boolean checkFaultAnalysis(String stockingRecordId,String mmId){
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 AND ICS_WR_Inactive__c = false];
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;
}
public static Boolean checkFaultAnalysis(String stockingRecordId,String mmId){
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 AND ICS_WR_Inactive__c = false];
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;
}
Assuming the above method is defined in a class named FaultAnalyzer, update your class as below
And then below test method should cover for the exception block
Hope this helps.
Lalit Mistry