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
Bill McBill Mc 

Scheduled Job starting but not executing

Hello

I have a Scheduled Job that runs on the 1st of each month at 3am.  It runs under my user account.

I can see from the debug logs that the jobs runs but for some reason there is no code executed.  The Apex class works fine when I call it via the Developer Console.

The class is defined as:

global class WhizzOppRenewer implements Schedulable, Database.Batchable<sObject>, Database.Stateful   {

  global void execute(SchedulableContext sc) {
        RenewOpps();
    }

  public static void RenewOpps()
   {
.....Create and start batch job...
   }

The log from 3am today is below. 

The Code unit is started and ended right away and I cannot understand why.

Can anyone help?

Bill


UserBill MclaughlinDate01/03/2016 03:00:01 GMT
StatusSuccessApplicationUnknown
Request TypeApplicationOperationWhizzOppRenewer
Duration (ms)692,028,902Log Size (bytes)1,002
Log33.0 APEX_CODE,DEBUG;APEX_PROFILING,INFO;CALLOUT,INFO;DB,INFO;SYSTEM,DEBUG;VALIDATION,INFO;VISUALFORCE,INFO;WORKFLOW,INFO 03:00:00.732 (732751375)|EXECUTION_STARTED 03:00:00.732 (732797036)|CODE_UNIT_STARTED|[EXTERNAL]|01pD0000001MNeb|WhizzOppRenewer 03:00:00.734 (734487130)|CUMULATIVE_LIMIT_USAGE 03:00:00.734 (734487130)|LIMIT_USAGE_FOR_NS|(default)| Number of SOQL queries: 0 out of 100 Number of query rows: 0 out of 50000 Number of SOSL queries: 0 out of 20 Number of DML statements: 0 out of 150 Number of DML rows: 0 out of 10000 Maximum CPU time: 0 out of 10000 Maximum heap size: 0 out of 6000000 Number of callouts: 0 out of 100 Number of Email Invocations: 0 out of 10 Number of future calls: 0 out of 50 Number of queueable jobs added to the queue: 0 out of 50 Number of Mobile Apex push calls: 0 out of 10 03:00:00.734 (734487130)|CUMULATIVE_LIMIT_USAGE_END 03:00:00.732 (734539526)|CODE_UNIT_FINISHED|WhizzOppRenewer 03:00:00.732 (735775005)|EXECUTION_FINISHED
venkat-Dvenkat-D
please post your batch class code to further debug the issue.
Bill McBill Mc
Hi there

Many thanks for your reply.

The code is quite involved and unique to our business objects. 

One thing I am not sure if it is causing an issue is that I instantiate a new instance of this same class (WhizzOppRenewer) from within the static method like so:

   // Create a new instance of this class with the target Opps
   WhizzOppRenewer wor = new WhizzOppRenewer(lstOpps);
    // start the batch execution
    Database.executeBatch(wor,10);


As I say, the class works fine when calling "WhizzOppRenewer.RenewOpps();" in Dev console execute anonymous window.



   The Batch relevant methods are below:
   
   global WhizzOppRenewer(List<Id> lstOppsIds){

        m_lstOppsIds = lstOppsIds;
                        
     System.Debug('In WhizzOppRenewer constructor');
     
    System.Debug('lstOppsIds.size()=' + lstOppsIds.size());

     for(Id id : lstOppsIds)
     {
       System.Debug('id=' + Id);
     }
     
     }
   
   // Start Method
  global List<Opportunity> start(Database.BatchableContext BC)
  {
     System.Debug('In WhizzOppRenewer start()');
     
    System.Debug('m_lstOppsIds.size()=' + m_lstOppsIds.size());

        m_lstOpps = [Select Id, Name, Account.Name from Opportunity where Id IN :m_lstOppsIds];

    System.Debug('m_lstOpps.size()=' + m_lstOpps.size());

     return m_lstOpps;
  }
   
   global void execute(Database.BatchableContext BC, list<Opportunity> lstOpps)
   {
    System.Debug('In WhizzOppRenewer.execute()...');

    System.Debug('lstOpps.size()=' + lstOpps.size());

    for(Opportunity opp : lstOpps)
    {
      System.Debug('Cloning Opp: ' + opp.id);

      catch(Exception e)
      {
        m_strErrors = m_strErrors + e.getMessage() + '\r\n';
        System.Debug(e.getMessage());
      }
    } 
    GlobalSetting.EnableOpportunitySetCancelledTrigger = true;
     
   }
   
   global void finish(Database.BatchableContext BC)
   {
     System.Debug('In WhizzOppRenewer finish()');

     // send me an email
     System.Debug('Beginning email...');
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        
        mail.setToAddresses(new String[] {'bill.mclaughlin@whizzeducation.com'});
        mail.setSubject('Renewed Opps');
        
        String body = 'The following ' + m_lstConedOpps.size() + ' Opportunities were renewed:\n\n';
        
    for(Opportunity opp :m_lstConedOpps)
    {
            body += opp.id + '     ' + opp.Name + '     ' + opp.Account.Name + '     ' +  '\n\n';
        }
        
        if(m_strErrors.Length()==0)
        {
          m_strErrors = 'No errors';
        }

        body += '\r\n\r\nThe following errors were reported: ' + '\r\n' + m_strErrors;
        
        mail.setPlainTextBody(body);
    
        if(!Test.isRunningTest()) {
            Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });                
        }

    GlobalSetting.EnableOpportunitySetCancelledTrigger = true;
        
    System.Debug('finished');
   
   }