2

I have a schedulable class in my package that would run every hour to pull data using a callout and put it in the custom object.

I am aware of using system.schedule as below:

String scheduleTime='0 '+currentMinute+' '+currentHour+' '+currentMonth+' '+currentYear+' ?'

system.schedule('MyJob', scheduleTime, new SchedulableC(context.installerId()));

I was wondering if there is a better way to run the job only ONCE after install.

1
  • 1
    quick 'n dirty: unschedule the job when it runs? – Matt and Neil Apr 19 '13 at 6:14
2

Wait a month, there is a new method in Summer '13 which does exactly this.

The new System.scheduleBatch method is handy for scheduling a batch job to run once at a future time. The only prerequisite is creating your batch class that implements the Database.Batchable interface. You don’t need to deal with the scheduling details, such as implementing the Schedulable interface or constructing a time and date (CronTrigger) expression.

Check the Summer 13 release notes for more details https://na1.salesforce.com/help/doc/en/salesforce_summer13_release_notes.pdf

1
  • Thanks for the suggestion :) But I can not wait for that long so I guess I will implement it so that job runs only once, since I am not allowed to make a callout oninstall. – sPaz Apr 20 '13 at 4:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.