{"id":1839,"date":"2009-11-12T03:27:37","date_gmt":"2009-11-11T22:27:37","guid":{"rendered":"http:\/\/www.chiragmehta.info\/chirag\/?p=1839"},"modified":"2011-11-23T11:20:58","modified_gmt":"2011-11-23T06:20:58","slug":"salesforce-schedule-apex-to-run-at-any-time-interval","status":"publish","type":"post","link":"https:\/\/www.chiragmehta.info\/chirag\/2009\/11\/12\/salesforce-schedule-apex-to-run-at-any-time-interval\/","title":{"rendered":"Salesforce &#8211; Schedule Apex to run at any time interval"},"content":{"rendered":"<p>Following is the snippet of anonymous code which will help you to schedule your apex for any interval. The Time parameter is not well structured and because of it I had to put in efforts in compiling the time parameter.<\/p>\n<blockquote><p><strong>Update (@23 Nov 2011) &#8211; Use below code to schedule apex class 10mins (change it as per your need) from now<\/strong><\/p>\n<p><strong>String str = system.now().addMinutes(10).format(&#8216;ss mm HH dd MM ? yyyy&#8217;);<\/strong><br \/>\n<strong>System.schedule(&#8216;Registration Report&#8217;, str , new scheduledApexClassName());<\/strong><\/p><\/blockquote>\n<p>\u00a0\u00a0<\/p>\n<p>I am documenting all the parameters neatly, which will help you to schedule apex to run at any time interval even minutes. Below code executes Apex every 10 minutes.<\/p>\n<blockquote><p>scheduledApexClassName m = new scheduledApexClassName();<\/p>\n<p>String seconds = &#8216;0&#8217;; \/\/Execute at Zero Seconds<br \/>\nString minutes = &#8216;10,20,30,40,50&#8217;; \/\/Execute at every 10th minute of hour<br \/>\nString hours = &#8216;*&#8217;; \/\/ Execute Every Hour<br \/>\nString dayOfMonth = &#8216;*&#8217;; \/\/ Execute Every Day of the Month<br \/>\nString month = &#8217;11&#8217;; \/\/Execute only in November(11)<br \/>\nString dayOfWeek = &#8216;?&#8217;; \/\/Execute on all 7 days of the Week<br \/>\nString year = &#8216;2009&#8217;; \/\/Execute only for year 2009<\/p>\n<p>\/\/Seconds Minutes Hours Day_of_month Month Day_of_week optional_year<br \/>\nString sch = seconds + &#8216; &#8216; + minutes + &#8216; &#8216; + hours + &#8216; &#8216; + dayOfMonth + &#8216; &#8216; + month + &#8216; &#8216; + dayOfWeek + &#8216; &#8216; + year;<br \/>\n\/\/String sch = &#8216;0 10,20,30,40,50 * * 11 ? 2009&#8217;;<\/p>\n<p>system.schedule(&#8216;Registration Report&#8217;, sch, m);<\/p><\/blockquote>\n<p>Execute above code in system log i.e., execute above annonymous code and it will schedule your Apex Class.<\/p>\n<p>For More Information on how to define a Schedule Apex Class refer <a href=\"http:\/\/na1.salesforce.com\/help\/doc\/en\/salesforce_winter10_release_notes.pdf#rn_162_apex_scheduler\">http:\/\/na1.salesforce.com\/help\/doc\/en\/salesforce_winter10_release_notes.pdf#rn_162_apex_scheduler<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Following is the snippet of anonymous code which will help you to schedule your apex for any interval. The Time parameter is not well structured and because of it I had to put in efforts in compiling the time parameter. Update (@23 Nov 2011) &#8211; Use below code to schedule apex class 10mins (change it [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[32],"tags":[169],"class_list":["post-1839","post","type-post","status-publish","format-standard","hentry","category-salesforce","tag-salesforce","post-preview"],"_links":{"self":[{"href":"https:\/\/www.chiragmehta.info\/chirag\/wp-json\/wp\/v2\/posts\/1839","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.chiragmehta.info\/chirag\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.chiragmehta.info\/chirag\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.chiragmehta.info\/chirag\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.chiragmehta.info\/chirag\/wp-json\/wp\/v2\/comments?post=1839"}],"version-history":[{"count":4,"href":"https:\/\/www.chiragmehta.info\/chirag\/wp-json\/wp\/v2\/posts\/1839\/revisions"}],"predecessor-version":[{"id":1841,"href":"https:\/\/www.chiragmehta.info\/chirag\/wp-json\/wp\/v2\/posts\/1839\/revisions\/1841"}],"wp:attachment":[{"href":"https:\/\/www.chiragmehta.info\/chirag\/wp-json\/wp\/v2\/media?parent=1839"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.chiragmehta.info\/chirag\/wp-json\/wp\/v2\/categories?post=1839"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.chiragmehta.info\/chirag\/wp-json\/wp\/v2\/tags?post=1839"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}