You need to sign in to do that
Don't have an account?
sumit d
code coverage in helper class of a trigger on case
Hi all, i have my helper class given below:-
public class BatchClosedResponse implements Database.Batchable<sObject> {
public Database.QueryLocator start(Database.BatchableContext BC){
string query = 'Select id, First_Response__c,'+
'ClosedDate ,'+
'OwnerId, CreatedDate, Status,'+
'Helper_Closed_Date__c, '+
'LastModifiedDate, '+
'Helper_First_Responce__c '+
'from case WHERE id = \'500m000000885qW\'';
System.debug('query'+query);
return Database.getQueryLocator(query);
}
public void execute(Database.BatchableContext BC, List<Case> scope){
List<Case> caseList = new List<Case>();
BusinessHours defaultBH = [ SELECT Id
FROM BusinessHours
WHERE IsDefault = true
Limit 1
];
for(Case caseObj : scope ){
if( (caseObj.ClosedDate != Null)
&& caseObj.Status == 'Closed'
){
System.debug('I am here');
Decimal lastResult = BusinessHours.diff( defaultBH.Id, caseObj.CreatedDate, caseObj.ClosedDate );
Decimal lastResultingHours = lastResult/(60*60*1000);
caseObj.Helper_Closed_Date__c= lastResultingHours;
}
caseList.add(caseObj);
}
update caseList;
}
public void finish(Database.BatchableContext BC){
}
}how to cover this part?
Any suggestion?
public class BatchClosedResponse implements Database.Batchable<sObject> {
public Database.QueryLocator start(Database.BatchableContext BC){
string query = 'Select id, First_Response__c,'+
'ClosedDate ,'+
'OwnerId, CreatedDate, Status,'+
'Helper_Closed_Date__c, '+
'LastModifiedDate, '+
'Helper_First_Responce__c '+
'from case WHERE id = \'500m000000885qW\'';
System.debug('query'+query);
return Database.getQueryLocator(query);
}
public void execute(Database.BatchableContext BC, List<Case> scope){
List<Case> caseList = new List<Case>();
BusinessHours defaultBH = [ SELECT Id
FROM BusinessHours
WHERE IsDefault = true
Limit 1
];
for(Case caseObj : scope ){
if( (caseObj.ClosedDate != Null)
&& caseObj.Status == 'Closed'
){
System.debug('I am here');
Decimal lastResult = BusinessHours.diff( defaultBH.Id, caseObj.CreatedDate, caseObj.ClosedDate );
Decimal lastResultingHours = lastResult/(60*60*1000);
caseObj.Helper_Closed_Date__c= lastResultingHours;
}
caseList.add(caseObj);
}
update caseList;
}
public void finish(Database.BatchableContext BC){
}
}how to cover this part?
Any suggestion?
In the SOQL query of start(), there is a record ID in where clause. When you try to test, it no records will be retrieved, as the test data inserted in test class will have a different record ID.
Any suggestion?
if( (caseObj.ClosedDate != Null)
&& caseObj.Status == 'Closed'
){
System.debug('I am here');
Decimal lastResult = BusinessHours.diff( defaultBH.Id, caseObj.CreatedDate, caseObj.ClosedDate );
Decimal lastResultingHours = lastResult/(60*60*1000);
caseObj.Helper_Closed_Date__c= lastResultingHours;
}
caseList.add(caseObj);
}
update caseList;
Any suggestion to cover this part?