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
BCDBSABCDBSA 

How to set up a VF page including buttons and date fields to run scheduled Apex class like scheduling reports

Hi All,

I have an Apex controller to a VF page. It will run everytime I click a button in the VF page. The controller works well. It's function is to clear a whole sObject old records and create a batch of new records.

When it comes to the second part to write a scheduled apex job, it is really confusing. There are a lot of posts about Apex Scheduler to run every hour or everyday. But would it be possible to set up a VF page just like the following (screenshot from Reports)? Users are able to choose wheter to start scheduling the apex job or stop scheduling; they can choose the date to start and cease; they can choose what time they would like the scheduled Apex job to run. 

I would like to know if it is doable. Any hints or sample codes are welcomed. If you have ever seen any post similar to it, please shart it to me!

Thanks!
User-added image
Best Answer chosen by BCDBSA
Chris Gary CloudPerformerChris Gary CloudPerformer
Ahh,
If you are interested in exposing an interface to users to let them schedule their batch jobs on their own schedule, then look at the 'Skoodat Relax' unmanaged package.  More information can be found at https://github.com/zachelrath/Relax .  In order to really schedule anything other than a very simple update, or delete, you will need to create a class that implements the Apex.Scheduleable interface, and most likely, the Database.Batchable interface as well.  Sadly, there really is no way around that.  I hope this helps you.  

Good Luck!

All Answers

Chris Gary CloudPerformerChris Gary CloudPerformer
This already exists for classes that implement the Apex.Scheduleable interface. You can access it in Setup > Develop > Apex Classes, and pressing the 'Schedule Apex' Button.
BCDBSABCDBSA
Hi Chris,

I know I can go to Setup and schedule Apex jobs like that, but what I really want is to let other users to choose time and frequency from the VF page. 

Would it be able to do that?

Thanks
Chris Gary CloudPerformerChris Gary CloudPerformer
Ahh,
If you are interested in exposing an interface to users to let them schedule their batch jobs on their own schedule, then look at the 'Skoodat Relax' unmanaged package.  More information can be found at https://github.com/zachelrath/Relax .  In order to really schedule anything other than a very simple update, or delete, you will need to create a class that implements the Apex.Scheduleable interface, and most likely, the Database.Batchable interface as well.  Sadly, there really is no way around that.  I hope this helps you.  

Good Luck!
This was selected as the best answer