2

I scheduled a weekly APEX Job and it is only staying as QUEUED Status.. What is strange is that the job actually runs (the data modifications occur) but it does not 'Complete'

Here is a class

Public Class resetIgnoreDuplicate {


    public static void resetContactFlag(){
        list <contact> contactsToUpdate = new list <contact>();
        list <contact> ignoredContacts = new list <contact>();

        ignoredContacts = [Select id, Ignore_Contact_Duplicate_Error__c from contact where Ignore_Contact_Duplicate_Error__c =TRUE ];

            if(ignoredContacts.size() > 0) 
            {
                for(contact c :ignoredContacts)
                    {
                        c.Ignore_Contact_Duplicate_Error__c = FALSE;
                        contactsToUpdate.add(c);
                    }

        database.SaveResult[] contactSR = database.update(contactsToUpdate,FALSE);
            for (Database.SaveResult sr : ContactSR) 
            {
              if (sr.isSuccess()) 
              {
               // Operation was successful, so get the ID of the record that was processed
                 System.debug('Successfully updated contact. Contact ID: ' + SR.getId());
               } 
               else 
               {
            // Operation failed, so get all errors
             for(Database.Error err : sr.getErrors())
                  {
                     System.debug('The following error has occurred.');
                      System.debug(err.getStatusCode() + ': ' + err.getMessage());
                      System.debug('Contact fields that affected this error: ' + err.getFields());
                  }
                }
             }
        }
     }

    public static void resetAccountFlag()
    {
        list <account> accountsToUpdate = new list <account>();
        list <Account> ignoredAccounts = new list <account>();
        ignoredAccounts = [Select id, Ignore_Duplicate_Error__c from account where Ignore_Duplicate_Error__c =TRUE ];

           if(ignoredaccounts.size() > 0) 
            {
                for(account a :ignoredAccounts)
                    {
                        a.Ignore_Duplicate_Error__c = FALSE;
                        accountstoupdate.add(a);
                    }

                database.SaveResult[] AccountSR=  database.update(accountstoupdate,false);

                  for (Database.SaveResult sr : AccountSR) 
            {
              if (sr.isSuccess()) 
              {
               // Operation was successful, so get the ID of the record that was processed
                 System.debug('Successfully updated Account. Account ID: ' + SR.getId());
               } 
               else 
               {
            // Operation failed, so get all errors
             for(Database.Error err : sr.getErrors())
                  {
                     System.debug('The following error has occurred.');
                      System.debug(err.getStatusCode() + ': ' + err.getMessage());
                      System.debug('Account fields that affected this error: ' + err.getFields());
                  }
                }
             }                                  
          }
        }



}

and my scheduleable class:

public class scheduledReset implements Schedulable {
   public void execute(SchedulableContext SC) {
       resetIgnoreDuplicate.resetContactFlag();
       resetIgnoreDuplicate.resetAccountFlag();
   }
}

Is there anything that stands out that would point to why this would occur?

2

Scheduled jobs requeue themselves automatically according to their Cron string. As such, they will remain queued forever until cancelled or the last execution occurs (e.g. because it's limited by the current year).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.