• Janna McNeil
  • NEWBIE
  • 0 Points
  • Member since 2015
  • Sales Operations Manager
  • Oxford Immunotec Inc.

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 3
    Replies
I am working to troubleshoot a batch Apex job that runs on a schedule but returns errors. I've read that I need to batch some of the queries but I have no idea how to do that. The Apex Job runs a batch update of all of our accounts from a couple of different custom objects. Any assistance or a point in the right direction would be greatly appreciated since I inherited this code. Thank you.

global class BatchUpdateAccounts implements Database.Batchable<sObject>, Database.Stateful {
      global final String query;
      global final Date inputDate;
      global Date maximumDate;
     
     
      global BatchUpdateAccounts(String q, Date d){
            query = q; 
            inputDate = d;
      }
     
       global Database.Querylocator start(Database.BatchableContext bc) {
            try {
                  Date d = Date.today();
                  Date targetDate;
                  if(d.month() == 1 || d.month() == 2 || d.month() == 3) {
                  targetDate = Date.newInstance(d.year(), 1, 1);
            }
            else if(d.month() == 4 || d.month() == 5 || d.month() == 6) {
                  targetDate = Date.newInstance(d.year(), 4, 1);
            }
            else if(d.month() == 7 || d.month() == 8 || d.month() == 9) {
                  targetDate = Date.newInstance(d.year(), 7, 1);
            }
            else {
                  targetDate = Date.newInstance(d.year(), 10, 1);
            }

Only a portion of the code is included here.
I am getting an error in challenger 2 and i am pretty sure all my headers are correct. The error is not really telling me much, can anyone help? thanks 

User-added image