You need to sign in to do that
Don't have an account?
Test class for my batch class
Hi ,
Please help me to write a test class for the below batch class written,
global class logdeletion implements Database.Batchable<sObject>{
public String query{get;set;}
public String email{get;set;}
//public Id toUserId{get;set;}
// public Id fromUserId{get;set;}
global Database.querylocator start(Database.BatchableContext BC){
return Database.getQueryLocator('Select Comments__c,Name,Owner,CreatedBy,LastModifiedBy,Date_TimeStamp__c,isSuccess__c,Report_URL__c,Result_String__c,Sample_Id__c,Sample_Stage__c FROM Log__c' );
}
global void execute(Database.BatchableContext BC, List<sObject> scope){
List<Log__c> Logs = new List<Log__c>();
for(sObject s : scope){
Log__c a = (Log__c)s;
}
delete Logs ;
//system.debug('batch apex called'+accns);
}
global void finish(Database.BatchableContext BC){
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setToAddresses(new String[] {email});
mail.setReplyTo('test@test.com');
//mail.setSenderDisplayName('SFDC Developer Organization');
//mail.setSubject('Batch Process');
//mail.setPlainTextBody('Batch Process has completed');
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
}
}Thanks
Hi,
Please check below URL and let me know if you have any question on top of it:-
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_batch_interface.htm
Happy to help you!
We can also call the individual methods in batch class.
Hi,
Its not working , its giving constructor not defined, below is my test class
@isTest
private class Testlogdeletion {
static testMethod void TestClass_logdeletion() {
Test.startTest();
List<Log__c> st=new List<Log__c>();
Database.BatchableContext bc;
logdeletion obj=new logdeletion();
//st=obj.start(bc);
Test.stopTest();
}
}
tHANKS
Hi just add below code snippet in your batch class and test class should be working fine.
Let me know if you still have any issue.
if i add the content below , my test is saving , but my scheduler class is not getting reflected when i try to schedule the class