+ Start a Discussion
ANKITAANKITA 

Reg: Scheduling Apex

Hi,

 

I have a class.

How can i execute this class each minute using scheduling apex?

 

Thanks,

ANKITA

Best Answer chosen by Admin (Salesforce Developers) 
Ankit AroraAnkit Arora
YourClassName m = new YourClassName();
String sch = '20 1 8 10 2 ?';
system.schedule('Job', sch, m);

 Here SCH represents : "Seconds Minutes Hours Day_of_month Month Day_of_week optional_year"

 

So you can change it accordingly.

 

For more reference over schedule jobs please visit : http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_scheduler.htm

 

Thanks

Ankit Arora

Blog | Facebook | Blog Page

All Answers

Ankit AroraAnkit Arora
YourClassName m = new YourClassName();
String sch = '20 1 8 10 2 ?';
system.schedule('Job', sch, m);

 Here SCH represents : "Seconds Minutes Hours Day_of_month Month Day_of_week optional_year"

 

So you can change it accordingly.

 

For more reference over schedule jobs please visit : http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_scheduler.htm

 

Thanks

Ankit Arora

Blog | Facebook | Blog Page

This was selected as the best answer
ANKITAANKITA

HI ANKIT,

Thanks

 

But this will execute @ 8:1:20 on 10day of 2nd month

20 1 8 10 2

at this time interval only.

I need to execute my class per each minute (daily).

 

Thanks,

ANKITA

ANKITAANKITA

Yes. I got it.

Its possible using

System.debug('-----------ScheduleMinute---------');

String hour = String.valueOf(Datetime.now().hour());

String min = String.valueOf(Datetime.now().minute() + 1);

String ss = String.valueOf(Datetime.now().second());

String nextFireTime = ss + ' ' + min + ' ' + hour + ' * * ?';

System.debug('-----------nextFireTime---------' + nextFireTime);

ScheduleMinute s = new ScheduleMinute();

System.schedule('Job Started At ' + String.valueOf(Datetime.now()), nextFireTime, s);



 

and goto Apex classes -> schedule apex -> and set the start date and end date here.

 

Thanks,

ANKITA