function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
garfergarfer 

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

 

UVUV

Use this approach-

static testMethod void testbatch(){
   
    Test.startTest();
    TestBatchClass job = new TestBatchClass();
    ID batchprocessid = Database.executeBatch(job);
    Test.stopTest();
}

garfergarfer

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