+ Start a Discussion
alexjalexj 

problem with class batch

Hi,

I have a problem with Batch class. Yesterday my class run correctly but I don't know what change I have do and that can't execute correctly.

My problem is that the fonction execute isn't realize and i don't understand why. 

I have create a simple class to understand but it the same problem.

Below, my class and the result of test.



Code Coverage BatchDelete (Code Covered: 75%)

 

global class BatchDelete implements Database.Batchable<sObject> {

           public String query; global BatchDelete(String q){

                    query=q;

           }

 

           global Database.QueryLocator start(Database.BatchableContext BC){

                      return Database.getQueryLocator(query);

           }

           global void execute(Database.BatchableContext BC, List<sObject> scope){

                      delete scope;

                      System.debug('fin execution');

          }

          global void finish(Database.BatchableContext BC){

           }

 

            public static testMethod void testBathDelete(){

                    List <Lead> ld = new List<Lead>();

                    for(integer i = 0; i<3; i++){

                                  Lead l = new Lead(Adresse_mail__c='testLead'+i+'@mail.com',LastName='nouveauprenom');

                                   ld.add(l);

                     }

                     insert ld;

                    Test.StartTest();

                    String q= 'SELECT ID, Name FROM Account LIMIT 3';

                    BatchDelete BD = new BatchDelete(q);

                    ID batchprocessid = Database.executeBatch(BD);

                    Test.StopTest();

            }

}

 

Best Answer chosen by Admin (Salesforce Developers) 
kiranmutturukiranmutturu

change that query object from account to lead and try

All Answers

kiranmutturukiranmutturu

r u getting any error while executing this?

kiranmutturukiranmutturu

from where you are invoking the batch class? if you are invoking through trigger then its not required to do the same in test class...check that also

alexjalexj

No there is no error. It's only write that the code is covered by 75% ans I can watch the part no-covered by the test (the fonction execute)

alexjalexj

for the moment I don't invoke the batch class, I do just "execute test" or I test with the developper's console

kiranmutturukiranmutturu

change that query object from account to lead and try

This was selected as the best answer
alexjalexj

i's ok, it's work.

Thank you