You need to sign in to do that
Don't have an account?
I have problems running a class using Apex Scheduler
I have a class called Sheduledfactura BatchLeadPhones and another call, I run the class with the second to run each month.
BatchLeadPhones class, is covered at 100%, but the Sheduledfactura not, how I can do to cover this class and you can run the scheduler.
Annex the code here
global class BatchLeadPhones implements Database.Batchable<sObject>{
public String query;
global database.querylocator start(Database.BatchableContext BC){
query='Select Id, Name, Nombre_del_Cliente__c From Factura__c';
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext BC, List<sObject> scope){
List<Factura__c> Leads = new List<Factura__c>();
for(sObject s : scope){
Factura__c l = (Factura__c)s;
l.Nombre_del_Cliente__c = 'Validada';
}
update Leads;
}
global void finish(Database.BatchableContext BC){
}
// test method
static testMethod void test_BatchLeadPhones() {
Test.StartTest();
BatchLeadPhones Blp = new BatchLeadPhones();
ID batchprocessid = Database.executeBatch(Blp);
Test.StopTest();
}
}
Sheduledfactura class
global class Sheduledfact implementsSchedulable{
global void execute(SchedulableContext SC){
BatchLeadPhones M =
newBatchLeadPhones();
database.executebatch(M);
String sch =
'0 0 5 * * ?';
system.schedule('Schedule TEST', sch, sh);
}
public
statictestMethodvoidtestschedule() {
Test.StartTest();
Sheduledfact sh =
newSheduledfact();
String sch =
'0 0 5 * * ?';
system
.schedule('Schedule TEST', sch, sh);
Test.stopTest();
}
}
I hope I can help with this
thanks
Use this approach-
static testMethod void testbatch(){
Test.startTest();
TestBatchClass job = new TestBatchClass();
ID batchprocessid = Database.executeBatch(job);
Test.stopTest();
}
Sorry, but this is my first class development, I can show where to put the code you tell me the code to cover 75%.
Thanks for your advice