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
RDSSRDSS 

I have batch class, it is getting executed and i have placed system.debug in it but only start method system.debug is getting tracked and entering in execute method but Lead . I am new to salesforce, please help. Below is my code

global class Batch_ABC implements Database.Batchable<sObject>
{
    list<lead> lstLeads = new list<Lead>();
    global string CISNumber;
    public string str='closed';     
    string Query ='select name, CIS_No__c, Status__c from opportunity where PRODUCT_CODE_FORMULA__c IN (891, 894, 915) AND Status__c =\'' + str + '\'';
    
    global database.QueryLocator start(Database.batchableContext bc)
    {
        System.debug(Query);
        system.debug('inside start');
        

        return database.getQueryLocator(Query);
    }
    
    global void execute(database.batchableContext bc, list<Opportunity> scope)
    {
        system.debug('inside Execute start');
        for(Opportunity o : scope)
        {
        system.debug('inside For loop of execute');

             CISNumber = o.CIS_No_MP__c;
             system.debug('inside execute.. CIS No : ' + CISNumber );

        }
        
        for(Account a : [select name, (Select ID, Name from Leads__r where Status = 'Closed - Converted' AND Loan_Cycle__c = 'K1' AND Product_Code__c IN (891, 894, 915)) from account where CNumber =: CSNumber])
        {
        system.debug('Inside second loop of execute...');

             for(lead l : a.Leads__r)
             {
                 system.debug('inside nested loop of execute...');
                   lstLeads.add(l);
             }
        }
        system.debug('Leads' + lstLeads);
        delete lstLeads ;
    }
    
    global void finish(database.batchableContext bc)
    {
    
    }
}
Harish RamachandruniHarish Ramachandruni
HI,


    Chack query is having reords or not in developer console .


Regards ,
Harish.R
Agustina GarciaAgustina Garcia
Batch processes are difficult to check on debug logs, as they can create many records in the log. Wich is exactly your issue?

Try to go to ApexJob screen and check if a new record with the name of your method has been created

User-added image

If there is a recod, look at the StatusDetail and TotalBatches colums. If status is Completed and TotalBatches is 0, it is because it is running but it is not doing anything at all.

If Status is Failed you can also check there the error. If the error is something like "Start did not return a valid iterable object" check your query (developer console maybe) because the result is not the expected one. 

If the query returns data, maybe it is something with your code. Try to create a simple account in your execute
 
Account acc = new Account();
acc.Name = 'Test';
insert acc;
Let me know if this doesn't help and we can look for another solution as well.

Agustina