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
alok29novalok29nov 

Scheduling apex jobs

Hi All,

 

I have some apex jobs which I need to run every week.Earlier,I used to run it through developer console but Now, I need to create unmanaged package for the apex jobs. So now my requirement is to automate it using apex classes.

 

Can anybody please provide me some code so that I can get started.

 

Thanks,

Alok

SamuelDeRyckeSamuelDeRycke

Have you looked at the documentation already ? I did this a while ago and fount it well explained. You'll need to look at apex scheduler and using batch apex

ForceMantis (Amit Jain)ForceMantis (Amit Jain)

Hi Alok

 

I am assuming you have written a Batch class that you execute using Database.executeBatch from developer console. If this so to solve the problem you need to create one more class for each Batch Job that Implement Schedulable interface of Apex.

Here is sample code, for more details you can refer salesforce documentation

 

global class scheduledBatchable implements Schedulable{
   global void execute(SchedulableContext sc) {
      batchable b = new batchable(); 
      database.executebatch(b);
   }
}

Just replace "batchable" with you batch class name. Hope this helps.