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
gaurav.sfdcgaurav.sfdc 

Schedule Job

I want to execute one Apex funxtion. I have created a class that implements schedulable in execute method I am writing a cron

... execute{
system.schedule( XYZ...)
myclass.function()
}

but when I go and see in setup/schedule jobs there are no jobs, do I need to do it from dveloper cconsol. I dont want to do this as I am creating a managed package so I just want as soon as my package gets installed a hourly job gets scheduled

James LoghryJames Loghry
If you have a class that implements the Schedulable interface, you will see it show up on the "Schedule Apex" button.  This button can be found at the top of the list of Apex classes in Setup->Develop->Classes.  Click on that, and you can schedule your class.  If you need it to run more frequently then every hour, then yes, you can schedule it via executeAnonymous like your small code snippet shows.

It should show up under the "Scheduled jobs" in your setup screen.  Make sure your list view on the schedule jobs page isn't hiding it.  If you still don't see it show up, then perhaps an error happened when you tried to schedule it.
gaurav.sfdcgaurav.sfdc
Thanks James, but is there any other way as we are creating a managed app. So as soon as any users install it, this schedule should be taken care by the app itself rather than any manual operation (button or executeAnonymous)?
James LoghryJames Loghry
Ah, I missed that part.  You should be able to call System.schedule inside of a PostInstall Script Apex class.  Note, you'll have to be smart about checking whether there is already a job scheduled (e.g. if the job has already been scheduled, but the package is being upgraded, for instance).  Note, I would be very thorough with your unit tests and also verification testing with this.

Here are a few links to get you started with InstallHandler classes (Post Install Scripts):
https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_install_handler.htm
http://zachelrath.wordpress.com/2012/09/06/migrate-your-post-install-and-uninstall-tasks-to-apex-install-scripts/
gaurav.sfdcgaurav.sfdc
Thanks James for quick reply, let me go through your links ...