System.schedule in Apex scheduler in Salsforce

Sample code:

SampleSchedulableClass obj = new SampleSchedulableClass();

String cron = '0 59 * * * *'
System.schedule('Testing', cron, obj);

The above code executes SampleSchedulableClass for every one hour.

Syntax for Cron:

Seconds Minutes Hours Day Month Week Year

Seconds : 0 - 59
Minutes  : 0 - 59
Hours     : 0 - 23
Day        : 1 - 31
Month    : 1 - 12
Week     : 1 - 7(Sunday is first and Saturday is last)
Year       : upto 2099

Year is optional.

Expression
Description
0 0 13 * * ?
Class runs every day at 1 PM.
0 0 22 ? * 6L
Class runs the last Friday of every month at 10 PM.
0 0 10 ? * MON-FRI
Class runs Monday through Friday at 10 AM.
0 0 20 * * ? 2010
Class runs every day at 8 PM during the year 2010.

? - No value
* - All values
L - Last
W - Nearest weekday

Cheers!!!

6 comments:

  1. Hi Magulan !

    I want the Visualforce code for creating register form & whenever user registers/creates his account, the form should automatically generate new password & should be sent in email to the user.?
    --> password must be same as username.

    I need Apex code & VF page for above task.
    thanks in advance...

    ReplyDelete
    Replies
    1. Hi,
      Kindly try it from your side and if you face any issue, I will help you.

      I can't work on entire logic.

      Cheers!!!

      Delete
    2. Any how I have learnt so many things from your blog......

      Cheers!!!

      Delete
  2. Hi,
    How to schedule a schedule class Dynamically from visualforce page?

    In an visualforce page I have 3 fields
    1)Start date(datetime fieldtype)
    2)enddate(datetime fieldtype)
    3)Frequency(datetime fieldtype)
    Note:Here my batch run between startdate and enddate based on frequency time and date
    Based on the above fields how to schedule my schedulable class?

    any one plese help me...................

    ReplyDelete
    Replies
    1. Hi Check this - http://www.infallibletechie.com/2012/05/apex-scheduler.html

      Cheers!!!

      Delete
  3. Magulan D,

    http://www.infallibletechie.com/2012/05/apex-scheduler.html

    I want that the above url page dynamically in an visualforce page how?

    Like below URL

    https://www.cloudclickware.com/jobbook/

    ReplyDelete