I am having trouble creating a test class for this particular class. If anyone could provide some code that would implement this I would be very grateful. Many thanks
CLASS
global class ModifiedDate implements Database.Batchable<sObject> {
List<Contact> ctt = new List<Contact>();
List<Account> acct = new List<Account>();
String query= 'SELECT Id,Name,Phone,LastModifiedDate,LastContact__c,(SELECT Id,AccountId,Name,Phone FROM Contacts) FROM Account WHERE Accountcheck__c = TRUE AND Donotruncontact_Management__c = FALSE';
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext BC, List<Account> scope) {
System.debug('!@#'+ scope);
for(Account acc: scope){
acc.LastContact__c = DateTime.now();
System.debug('!@#'+acc.LastContact__c);
for(Contact ctct: acc.Contacts){
ctct.Phone = acc.Phone;
ctt.add(ctct);
System.debug('!@#'+ctct.Phone);
}
acct.add(acc);
}
update acct;
System.debug('!@#'+ acct);
update ctt;
System.debug('!@#'+ ctt);
}
global void finish(Database.BatchableContext BC) {
//code to do when the batch job finished
System.debug('>>>>> Finish Execution: ' + System.now().format());
}
}
TEST CLASS
@isTest
public with sharing class ModifiedDate_Test {
public ModifiedDate_Test() {
// Implement test code
System.Test.startTest();
String query = 'SELECT Id,Name,Phone,LastModifiedDate,LastContact__c,(SELECT Id,AccountId,Name,Phone FROM Contacts) FROM Account WHERE Accountcheck__c = TRUE AND Donotruncontact_Management__c = FALSE';
ModifiedDate sf = new ModifiedDate_Test(query);
Database.executeBatch(sf);
System.Test.stopTest();
}
}