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
LuciferLucifer 

Argument must be an object that implements Database.Batchable

Im trying to run a batch apex for my code

 

/************************************************************************/

EscalateAnnualEnrollmentTaskProcess AE = new EscalateAnnualEnrollmentTaskProcess();
database.executebatch(AE);


/************************************************************************/


global class TaskProcess implements Schedulable {
   global void execute(SchedulableContext ctx) 
   {
      /*  */
      List<Request__c> requestIds = [SELECT Id FROM Request__c WHERE status__c != 'ACCEPTED'];
      /* list of tasks associated near overdue activitydate - 5*/
      List<Task>Overdue =new List<Task>([SELECT Id, ActivityDate, Subject FROM Task WHERE WhatId IN :requestIds AND IsClosed = false]);
      /* iterate over the tasks */
      for (Task t:tasksNearOverdue) {
         /* lookup the object */
         Request__c request = [SELECT Id, Project_Manager__c, Director__c FROM Request__c WHERE Id = :t.WhatId];
 

         /* lookup the user and send the email*/
         User manager = [SELECT Id, Name, Email FROM User WHERE Id = :request.Project_Manager__c];
         sendemail(projectmanager, t);
         /* lookup the user and send the email */
         User director =  [SELECT Id, Name, Email FROM User WHERE Id = :request.Director__c];
         sendemail(director, t);
      }
   
 } 
   global void sendemail(User u, Task t)
   {
      Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
      string[] toaddress = New String[] {u.Email};
      email.setSubject('Task Almost Overdue');
      email.setPlainTextBody(t.Subject + 'is due ' + t.ActivityDate + ' and needs some attention.');
      email.setToAddresses(toaddress);
      Messaging.sendEmail(New Messaging.SingleEmailMessage[] {email});
   }
}

Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

This is because you are implementing the schedulable rather than batchable interface  Shedulable allows apex code to be scheduled, but you can't invoke executebatch on it.

All Answers

LuciferLucifer

It is giving me the error " Argument must be an object that implements Database.Batchable"

bob_buzzardbob_buzzard

This is because you are implementing the schedulable rather than batchable interface  Shedulable allows apex code to be scheduled, but you can't invoke executebatch on it.

This was selected as the best answer
LuciferLucifer

Thanks Bob. This code is for email alerts for the project manager and Directors for Overdue tasks. I wanted to see if the code is working.. How do I test for schedulable jobs

LuciferLucifer

Thanks Bob.. I wil figure it out..

SAKTHIVEL MSAKTHIVEL M

Hi,

 

In your apex class add the (implements Database.Batchable<sObject>) line,

instead of implements Schedulable

 

For Ex,

 

global class TaskProcess implements Database.Batchable<sObject> {

//your code

 

for more info read theblogreaders.com