Wednesday, June 6, 2012

How to Schedule job from Schedule Job

Salesforce only adds the process to the queue at the scheduled time. Actual execution may be delayed based on service availability.

You can only have 25 classes scheduled at one time. You can evaluate your current count by viewing the Scheduled Jobs page in Salesforce or programmatically using SOAP API to query the CronTrigger object.

When we schedule a class, cron expression plays an important role to decide the next scheduled time of the class. Please refer the following link for more details about cron expression.

In the below code sample the cron expression is built in such a way so that it will not schedule the job in future.I have used the year parameter in cron expression which will not schedule the same class again.

global class scheduledJobController implements Schedulable{
   global void execute(SchedulableContext SC) {
       try {
         // TO DO LOGIC
       catch(Exception e) {
         // TO DO Log error
       finally {
            Datetime currentTime =;
            Datetime newTime = currentTime.addSeconds(20);
            // build cron expression
            String sch= String.valueOf(newtime.second()) +' ' + String.valueOf(newtime.minute()) + ' ' + String.valueOf(newTime.hour()) + ' ' + String.valueOf( + ' ' + String.valueOf(newTime.month()) + ' ? ' +  String.valueOf(newTime.year());
            scheduledJobController scheduleObject = new scheduledJobController();
            Id sId = system.schedule('scheduledJobController'+newTime , sch, scheduleObject );  


  1. I am really happy with your blog because your article is very unique and powerful for new reader.
    Click here:
    Selenium Training in Chennai | Selenium Training in Bangalore | Selenium Training in Pune | Selenium Training in Chennai

  2. Hi, thank you very much for new information , i learned something new. Very well written. It was so good to read and usefull to improve knowledge. Keep posting. If you are looking for any python related information please visit our website python training in pune.

  3. thanks for your article it's very and useful thanks for it i got many information web design company in velachery

  4. Post is very useful. Thank you, this useful information.

    Upgrade your career Learn Oracle Training from industry experts gets complete hands on Training, Interview preparation, and Job Assistance at Softgen Infotech.

  5. Thanks mate. I am really impressed with your writing talents and also with the layout on your weblog. Appreciate, Is this a paid subject matter or did you customize it yourself? Either way keep up the nice quality writing, it is rare to peer a nice weblog like this one nowadays. Thank you, check also event marketing and Marketing Funnel

  6. Yet again yet again a couple of times, you can defer and restart exercises; the result results can be protected and imported, similarly as at whatever point you restart, there is compelling reason need to check. Easeus Data Recovery Wizard License Code

  7. I have Been addressing pretty much this count number, as a final product gratitude for posting. cold publication.It 's as a matter of fact exceptionally fine and helpful say.thank you Happy Birthday Famous Quotes