+ Start a Discussion
Claire SunderlandClaire Sunderland 

I want to batch delete all completed activities on a lead page with the subject 'callback.' The following pictures show the Batch Apex Class and Batch Test I have but they are not working. Does anyone have any tips?

User-added image

User-added image
Best Answer chosen by Claire Sunderland
Abhishek BansalAbhishek Bansal
Hi Claire,

Please follow the steps as mentioned below:

1. Create new apex class and paste the code as mentioned below:
global class DeleteAllTaskScheduler implements Schedulable{
  global void execute(SchedulableContext sc) {  
      DeleteAllTask batch = new DeleteAllTask();
      Id batchId = database.executeBatch(batch,50);   
  }
}
2. Now open the Developer Console
3. Click on the Debug drop-down at the top left corner.
4. Now Select Open Execute Anonymous window.
5. Clear everything in the window and paste the code as mentioned below:
DeleteAllTaskScheduler sec = new DeleteAllTaskScheduler();   
String cronStr = '0 0 22 1/1 * ? *';                            
System.schedule('Schedule To Delete Tasks', cronStr, sec);
6. Now click on the Execute button and make sure that there is no error.
7. Now you can check in your scheduled jobs that the batch is scheduled to run on the daily basis at 10:00 pm.


Please let me know if you still need any other help.

Thanks,
Abhishek Bansal.

All Answers

Abhishek BansalAbhishek Bansal

Hi Clarie,

Your batch class looks fine to me. Have you ran your batch class or schedule it from developer console? What is not working for you? Test class is not showing proper coverage or batch is not running properly through developer console? Please clarify.

Thanks,
Abhishek Bansal.

Claire SunderlandClaire Sunderland
I probably haven't run or scheduled it!  This is the first time I've done a batch so I'm not exactly sure how it works.  I pushed it from developer to production but do I need to do something else also?
Claire SunderlandClaire Sunderland
I want it to run every night.  What do I need to do to implement that?
Abhishek BansalAbhishek Bansal
Hi Claire,

You need to follow the below mentioned steps in order to run this batch every night:
  1. Create a scheduler class for this batch.
  2. Create a crone expression that will schedule this class to run every night.
  3. Now using developer console you can schedule your batch class.

Please let me know if you need any further help on this. You can also contact me on Gmail or Skype if anything is urgent:
Gmail: abhibansal2790@gmail.com
Skype: abhishek.bansal2790

Thanks,
Abhishek Bansal.

Claire SunderlandClaire Sunderland
Thanks Abhishek - I actually do need help with this as I have never built any of those before!  If you have time would you send me what those should look like?
Abhishek BansalAbhishek Bansal
Hi Claire,

Please follow the steps as mentioned below:

1. Create new apex class and paste the code as mentioned below:
global class DeleteAllTaskScheduler implements Schedulable{
  global void execute(SchedulableContext sc) {  
      DeleteAllTask batch = new DeleteAllTask();
      Id batchId = database.executeBatch(batch,50);   
  }
}
2. Now open the Developer Console
3. Click on the Debug drop-down at the top left corner.
4. Now Select Open Execute Anonymous window.
5. Clear everything in the window and paste the code as mentioned below:
DeleteAllTaskScheduler sec = new DeleteAllTaskScheduler();   
String cronStr = '0 0 22 1/1 * ? *';                            
System.schedule('Schedule To Delete Tasks', cronStr, sec);
6. Now click on the Execute button and make sure that there is no error.
7. Now you can check in your scheduled jobs that the batch is scheduled to run on the daily basis at 10:00 pm.


Please let me know if you still need any other help.

Thanks,
Abhishek Bansal.
This was selected as the best answer
Claire SunderlandClaire Sunderland
Awesome - thank you so much for your help, Abhishek! I will try this and mark if it worked for me.