<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Daily cron jobs with Apex</title>
	<atom:link href="http://gokubi.com/archives/daily-cron-jobs-with-apex/feed" rel="self" type="application/rss+xml" />
	<link>http://gokubi.com/archives/daily-cron-jobs-with-apex</link>
	<description></description>
	<lastBuildDate>Thu, 04 Mar 2010 13:37:32 -0700</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Forcedotcom</title>
		<link>http://gokubi.com/archives/daily-cron-jobs-with-apex/comment-page-1#comment-197852</link>
		<dc:creator>Forcedotcom</dc:creator>
		<pubDate>Wed, 25 Nov 2009 12:29:20 +0000</pubDate>
		<guid isPermaLink="false">http://gokubi.com/archives/daily-cron-jobs-with-apex#comment-197852</guid>
		<description>This is fantastic - thank you.</description>
		<content:encoded><![CDATA[<p>This is fantastic &#8211; thank you.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: vivek</title>
		<link>http://gokubi.com/archives/daily-cron-jobs-with-apex/comment-page-1#comment-190916</link>
		<dc:creator>vivek</dc:creator>
		<pubDate>Thu, 24 Sep 2009 06:57:44 +0000</pubDate>
		<guid isPermaLink="false">http://gokubi.com/archives/daily-cron-jobs-with-apex#comment-190916</guid>
		<description>has SFDC put any scheduling interface for Apex blocks? pls let me know</description>
		<content:encoded><![CDATA[<p>has SFDC put any scheduling interface for Apex blocks? pls let me know</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: cog</title>
		<link>http://gokubi.com/archives/daily-cron-jobs-with-apex/comment-page-1#comment-168276</link>
		<dc:creator>cog</dc:creator>
		<pubDate>Sat, 11 Apr 2009 03:43:37 +0000</pubDate>
		<guid isPermaLink="false">http://gokubi.com/archives/daily-cron-jobs-with-apex#comment-168276</guid>
		<description>Ron, Jessie, Steve

Have the same problem. I guess updating the same record again doesn&#039;t help anymore. I tried inserting new records and it works, but not the update. I guess this is what is preventing:
When a record is created, or when a record is edited and did not previously meet the rule criteria
Correct me if i am wrong. I tried it and is not firing the rule the second time, after it is updated in the trigger. Wondering how to fool the rule to think that it didn&#039;t meet the criteria previously. Guess thats not possible!</description>
		<content:encoded><![CDATA[<p>Ron, Jessie, Steve</p>
<p>Have the same problem. I guess updating the same record again doesn&#8217;t help anymore. I tried inserting new records and it works, but not the update. I guess this is what is preventing:<br />
When a record is created, or when a record is edited and did not previously meet the rule criteria<br />
Correct me if i am wrong. I tried it and is not firing the rule the second time, after it is updated in the trigger. Wondering how to fool the rule to think that it didn&#8217;t meet the criteria previously. Guess thats not possible!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: joe-ferraro.com &#124; running a trigger via workflow</title>
		<link>http://gokubi.com/archives/daily-cron-jobs-with-apex/comment-page-1#comment-119003</link>
		<dc:creator>joe-ferraro.com &#124; running a trigger via workflow</dc:creator>
		<pubDate>Mon, 04 Aug 2008 20:55:17 +0000</pubDate>
		<guid isPermaLink="false">http://gokubi.com/archives/daily-cron-jobs-with-apex#comment-119003</guid>
		<description>[...] of you who follow Steve Andersen&#8217;s blog may have seen his post re: cron jobs using Apex in April 2007. Kudos to you, Steve for a fantastic post (better late than never!) not only because [...]</description>
		<content:encoded><![CDATA[<p>[...] of you who follow Steve Andersen&#8217;s blog may have seen his post re: cron jobs using Apex in April 2007. Kudos to you, Steve for a fantastic post (better late than never!) not only because [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Zodeno.com &#187; Stupid Salesforce.com + Google.com Trick (or, Calendar + GMAIL + Email2Apex = hacky cron)</title>
		<link>http://gokubi.com/archives/daily-cron-jobs-with-apex/comment-page-1#comment-116420</link>
		<dc:creator>Zodeno.com &#187; Stupid Salesforce.com + Google.com Trick (or, Calendar + GMAIL + Email2Apex = hacky cron)</dc:creator>
		<pubDate>Sat, 26 Jul 2008 01:30:18 +0000</pubDate>
		<guid isPermaLink="false">http://gokubi.com/archives/daily-cron-jobs-with-apex#comment-116420</guid>
		<description>[...] One of the things salesforce.com lacks is a decent analog to &#8220;cron&#8221;, the ubiquitous unix/linux job scheduling tool. This is a kludgey but mildly amusing solution. (Here&#8217;s a simple, less kludgey cron that&#8217;s all native SFDC, which is probably a better i... [...]</description>
		<content:encoded><![CDATA[<p>[...] One of the things salesforce.com lacks is a decent analog to &#8220;cron&#8221;, the ubiquitous unix/linux job scheduling tool. This is a kludgey but mildly amusing solution. (Here&#8217;s a simple, less kludgey cron that&#8217;s all native SFDC, which is probably a better i&#8230; [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Stupid Salesforce.com + Google.com Trick (or, Calendar + GMAIL + Email2Apex = hacky cron) &#8212; Reid Carlberg: Misc. Notes</title>
		<link>http://gokubi.com/archives/daily-cron-jobs-with-apex/comment-page-1#comment-115632</link>
		<dc:creator>Stupid Salesforce.com + Google.com Trick (or, Calendar + GMAIL + Email2Apex = hacky cron) &#8212; Reid Carlberg: Misc. Notes</dc:creator>
		<pubDate>Wed, 23 Jul 2008 13:13:10 +0000</pubDate>
		<guid isPermaLink="false">http://gokubi.com/archives/daily-cron-jobs-with-apex#comment-115632</guid>
		<description>[...] One of the things salesforce.com lacks is a decent analog to &#8220;cron&#8221;, the ubiquitous unix/linux job scheduling tool. This is a kludgey but mildly amusing solution. (Here&#8217;s a simple, less kludgey cron that&#8217;s all native SFDC, which is probably a better i... [...]</description>
		<content:encoded><![CDATA[<p>[...] One of the things salesforce.com lacks is a decent analog to &#8220;cron&#8221;, the ubiquitous unix/linux job scheduling tool. This is a kludgey but mildly amusing solution. (Here&#8217;s a simple, less kludgey cron that&#8217;s all native SFDC, which is probably a better i&#8230; [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jessie Grenfell</title>
		<link>http://gokubi.com/archives/daily-cron-jobs-with-apex/comment-page-1#comment-101039</link>
		<dc:creator>Jessie Grenfell</dc:creator>
		<pubDate>Mon, 19 May 2008 15:08:32 +0000</pubDate>
		<guid isPermaLink="false">http://gokubi.com/archives/daily-cron-jobs-with-apex#comment-101039</guid>
		<description>Ron, 

I hit the same problem and adjusted my code to create a new BatchObject (which I call Scheduled_Job__c) record every time it gets set off, instead of updating the same record.  It gives me a log of what&#039;s happened, and I then have a method, also run by the batch routine, that deletes old Scheduled_Job__c records to keep things clean.  

This approach also works for me because I wrote my routine to process records in chunks that I know won&#039;t set off the governor limits (always a battle), so the code generates a new Scheduled_Job__c to run immediately until all records are processed and then schedules itself again for the next night at midnight.   You just need some way to track which records have been processed already, which I do by just adding a timestamp field to the records that I&#039;m processing that gets updated when the batch is run.  I&#039;ve used it to run some typical batch processes and also to send out a dynamic email each night to a bunch of users, where I&#039;m limited to sending to 10 email addresses at one time and about 40 people need to receive it.  

It&#039;s a hack on a hack on a hack, but it works!  Luckily, I&#039;m nowhere near hitting the limit on workflow time triggers per day.  This is the trigger I&#039;m using-


trigger InsertUpdateScheduledJobAfter on Scheduled_Job__c (after insert, after update) {
	Integer intReturn;
	Integer intMagicNum;
	
	for (Scheduled_Job__c sj : Trigger.new){
		if (sj.Run_Job__c == true){
			
			//Create Site Log records for 7 business days in the future, if needed
			if (sj.Method_To_Execute__c == &#039;CreateSiteLogs&#039;){
				intReturn = clsScheduledJobs.CreateSiteLogs(null);
				//This job is run in batches of 2 site invoices (the max that can be processed
				//before hitting the governor limit), so less than 2 means it&#039;s done
				intMagicNum = 2;
			} 
			
			//Send out Job Loss Report
			if (sj.Method_To_Execute__c == &#039;JobLossReport&#039;){
				intReturn = clsScheduledJobs.JobLossReport();
				//Single email limited to 10 at a time
				intMagicNum = 10;
			}
			
			if (sj.Method_To_Execute__c == &#039;ScheduledJobCleanup&#039;){
				intReturn = clsScheduledJobs.ScheduledJobCleanup();
				//This job always returns 0, shouldn&#039;t need to be re-run anytime soon
				intMagicNum = 1;
			}
			Scheduled_Job__c new_sj = new Scheduled_Job__c(
				Method_To_Execute__c = sj.Method_To_Execute__c,
				Name = sj.Name,
				Run_Job__c = false,
				Schedule__c = true);
			
			//If the number returned by the method is less than the Magic Number, 
			//create a Scheduled Job record to run it again tomorrow night	
			if (intReturn &lt; intMagicNum){
				
				//Reset Scheduled Job record to midnight of tomorrow
				new_sj.Next_Run_Datetime__c = Datetime.newInstance(System.today().year(), System.today().month(), System.today().day()).addDays(1);
				
			//Otherwise, there are more records to process, so create a record 
			//to run it again immediately
			} else {
				new_sj.Next_Run_Datetime__c = System.now();
				
			}
			
			insert new_sj;
		}
		
	}
}</description>
		<content:encoded><![CDATA[<p>Ron, </p>
<p>I hit the same problem and adjusted my code to create a new BatchObject (which I call Scheduled_Job__c) record every time it gets set off, instead of updating the same record.  It gives me a log of what&#8217;s happened, and I then have a method, also run by the batch routine, that deletes old Scheduled_Job__c records to keep things clean.  </p>
<p>This approach also works for me because I wrote my routine to process records in chunks that I know won&#8217;t set off the governor limits (always a battle), so the code generates a new Scheduled_Job__c to run immediately until all records are processed and then schedules itself again for the next night at midnight.   You just need some way to track which records have been processed already, which I do by just adding a timestamp field to the records that I&#8217;m processing that gets updated when the batch is run.  I&#8217;ve used it to run some typical batch processes and also to send out a dynamic email each night to a bunch of users, where I&#8217;m limited to sending to 10 email addresses at one time and about 40 people need to receive it.  </p>
<p>It&#8217;s a hack on a hack on a hack, but it works!  Luckily, I&#8217;m nowhere near hitting the limit on workflow time triggers per day.  This is the trigger I&#8217;m using-</p>
<p>trigger InsertUpdateScheduledJobAfter on Scheduled_Job__c (after insert, after update) {<br />
	Integer intReturn;<br />
	Integer intMagicNum;</p>
<p>	for (Scheduled_Job__c sj : Trigger.new){<br />
		if (sj.Run_Job__c == true){</p>
<p>			//Create Site Log records for 7 business days in the future, if needed<br />
			if (sj.Method_To_Execute__c == &#8216;CreateSiteLogs&#8217;){<br />
				intReturn = clsScheduledJobs.CreateSiteLogs(null);<br />
				//This job is run in batches of 2 site invoices (the max that can be processed<br />
				//before hitting the governor limit), so less than 2 means it&#8217;s done<br />
				intMagicNum = 2;<br />
			} </p>
<p>			//Send out Job Loss Report<br />
			if (sj.Method_To_Execute__c == &#8216;JobLossReport&#8217;){<br />
				intReturn = clsScheduledJobs.JobLossReport();<br />
				//Single email limited to 10 at a time<br />
				intMagicNum = 10;<br />
			}</p>
<p>			if (sj.Method_To_Execute__c == &#8216;ScheduledJobCleanup&#8217;){<br />
				intReturn = clsScheduledJobs.ScheduledJobCleanup();<br />
				//This job always returns 0, shouldn&#8217;t need to be re-run anytime soon<br />
				intMagicNum = 1;<br />
			}<br />
			Scheduled_Job__c new_sj = new Scheduled_Job__c(<br />
				Method_To_Execute__c = sj.Method_To_Execute__c,<br />
				Name = sj.Name,<br />
				Run_Job__c = false,<br />
				Schedule__c = true);</p>
<p>			//If the number returned by the method is less than the Magic Number,<br />
			//create a Scheduled Job record to run it again tomorrow night<br />
			if (intReturn &lt; intMagicNum){</p>
<p>				//Reset Scheduled Job record to midnight of tomorrow<br />
				new_sj.Next_Run_Datetime__c = Datetime.newInstance(System.today().year(), System.today().month(), System.today().day()).addDays(1);</p>
<p>			//Otherwise, there are more records to process, so create a record<br />
			//to run it again immediately<br />
			} else {<br />
				new_sj.Next_Run_Datetime__c = System.now();</p>
<p>			}</p>
<p>			insert new_sj;<br />
		}</p>
<p>	}<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ron</title>
		<link>http://gokubi.com/archives/daily-cron-jobs-with-apex/comment-page-1#comment-77462</link>
		<dc:creator>Ron</dc:creator>
		<pubDate>Thu, 31 Jan 2008 17:10:28 +0000</pubDate>
		<guid isPermaLink="false">http://gokubi.com/archives/daily-cron-jobs-with-apex#comment-77462</guid>
		<description>I&#039;m curious, does this approach still work?   I&#039;ve been playing with the same type of approach and have run into a roadblock (making me think Salesforce may have made changes to the way they process triggers and workflow):

The general flow goes like this (I&#039;ve simplified the debug output for brevity sake) ...

BatchObject is modified, RunBatchJob=true.

Beginning triggerX on BatchObject (After Update)
       Batch job runs and sets RunBatchJob=false

       Beginning triggerX on BatchObject (After Update)
               This time RunBatchJob=false, so no action taken.
       Ending triggerX
 
       Beginning Workflow Evaluation
               RunBatchJob=false so criteria evaluates to true and time-based action is queued.
       Ending workflow evaluation

Ending triggerX

Beginning Workflow Evaluation
      RunBatchJob=true  (!! apparently the original version of BatchObject) so criteria evaluates to false and time-based action is removed from queue
Ending workflow evaluation


How do I stop the Workflow Evaluation at the end from occuring and undoing my work?  I&#039;ve tried setting separate flags for &quot;run apex&quot; and &quot;run scheduler&quot;, and I&#039;ve run the trigger before and after update, but before the trigger/workflow cycle can complete, my trigger has to update a field used in the workflow rule and this problem re-appears.</description>
		<content:encoded><![CDATA[<p>I&#8217;m curious, does this approach still work?   I&#8217;ve been playing with the same type of approach and have run into a roadblock (making me think Salesforce may have made changes to the way they process triggers and workflow):</p>
<p>The general flow goes like this (I&#8217;ve simplified the debug output for brevity sake) &#8230;</p>
<p>BatchObject is modified, RunBatchJob=true.</p>
<p>Beginning triggerX on BatchObject (After Update)<br />
       Batch job runs and sets RunBatchJob=false</p>
<p>       Beginning triggerX on BatchObject (After Update)<br />
               This time RunBatchJob=false, so no action taken.<br />
       Ending triggerX</p>
<p>       Beginning Workflow Evaluation<br />
               RunBatchJob=false so criteria evaluates to true and time-based action is queued.<br />
       Ending workflow evaluation</p>
<p>Ending triggerX</p>
<p>Beginning Workflow Evaluation<br />
      RunBatchJob=true  (!! apparently the original version of BatchObject) so criteria evaluates to false and time-based action is removed from queue<br />
Ending workflow evaluation</p>
<p>How do I stop the Workflow Evaluation at the end from occuring and undoing my work?  I&#8217;ve tried setting separate flags for &#8220;run apex&#8221; and &#8220;run scheduler&#8221;, and I&#8217;ve run the trigger before and after update, but before the trigger/workflow cycle can complete, my trigger has to update a field used in the workflow rule and this problem re-appears.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Scott Morrison</title>
		<link>http://gokubi.com/archives/daily-cron-jobs-with-apex/comment-page-1#comment-75263</link>
		<dc:creator>Scott Morrison</dc:creator>
		<pubDate>Tue, 15 Jan 2008 23:22:10 +0000</pubDate>
		<guid isPermaLink="false">http://gokubi.com/archives/daily-cron-jobs-with-apex#comment-75263</guid>
		<description>Nice work! I&#039;ve taken the concept a bit further to allow time based hourly and daily scripts. http://scott.morrisonlive.ca/sfSimpleBlog/show/stripped_title/time-based-batch-scripts-in-salesforce</description>
		<content:encoded><![CDATA[<p>Nice work! I&#8217;ve taken the concept a bit further to allow time based hourly and daily scripts. <a href="http://scott.morrisonlive.ca/sfSimpleBlog/show/stripped_title/time-based-batch-scripts-in-salesforce" rel="nofollow">http://scott.morrisonlive.ca/sfSimpleBlog/show/stripped_title/time-based-batch-scripts-in-salesforce</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chris</title>
		<link>http://gokubi.com/archives/daily-cron-jobs-with-apex/comment-page-1#comment-34028</link>
		<dc:creator>Chris</dc:creator>
		<pubDate>Wed, 06 Jun 2007 20:49:24 +0000</pubDate>
		<guid isPermaLink="false">http://gokubi.com/archives/daily-cron-jobs-with-apex#comment-34028</guid>
		<description>Love it - great work, Steve!</description>
		<content:encoded><![CDATA[<p>Love it &#8211; great work, Steve!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Harm Korten</title>
		<link>http://gokubi.com/archives/daily-cron-jobs-with-apex/comment-page-1#comment-25643</link>
		<dc:creator>Harm Korten</dc:creator>
		<pubDate>Fri, 04 May 2007 11:50:01 +0000</pubDate>
		<guid isPermaLink="false">http://gokubi.com/archives/daily-cron-jobs-with-apex#comment-25643</guid>
		<description>Very nice ! Like with many issues, which can only be solved with work arounds or external resources at the moment, APEX will do the trick. Very nice solution to run batches. Our company has developped quite a lot of batchtasks for customers, all hosted on external servers. I think your APEX solution will make running batches even easier in the future.</description>
		<content:encoded><![CDATA[<p>Very nice ! Like with many issues, which can only be solved with work arounds or external resources at the moment, APEX will do the trick. Very nice solution to run batches. Our company has developped quite a lot of batchtasks for customers, all hosted on external servers. I think your APEX solution will make running batches even easier in the future.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Raja</title>
		<link>http://gokubi.com/archives/daily-cron-jobs-with-apex/comment-page-1#comment-23942</link>
		<dc:creator>Raja</dc:creator>
		<pubDate>Wed, 25 Apr 2007 16:46:58 +0000</pubDate>
		<guid isPermaLink="false">http://gokubi.com/archives/daily-cron-jobs-with-apex#comment-23942</guid>
		<description>Hello Folks,
Wanted to give you an update on the limits. Please disregard the earlier numbers.
The limits are as follows:
â€¢	Unlimited Edition=20,000 time triggers per org
â€¢	Enterprise Edition=10,000 time triggers per org

For the latest numbers, please refer to the FAQ, which i will be posting soon on Time-based workflow feature detail page on successforce.com website.</description>
		<content:encoded><![CDATA[<p>Hello Folks,<br />
Wanted to give you an update on the limits. Please disregard the earlier numbers.<br />
The limits are as follows:<br />
â€¢	Unlimited Edition=20,000 time triggers per org<br />
â€¢	Enterprise Edition=10,000 time triggers per org</p>
<p>For the latest numbers, please refer to the FAQ, which i will be posting soon on Time-based workflow feature detail page on successforce.com website.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kingsley</title>
		<link>http://gokubi.com/archives/daily-cron-jobs-with-apex/comment-page-1#comment-23500</link>
		<dc:creator>Kingsley</dc:creator>
		<pubDate>Mon, 23 Apr 2007 17:35:14 +0000</pubDate>
		<guid isPermaLink="false">http://gokubi.com/archives/daily-cron-jobs-with-apex#comment-23500</guid>
		<description>Fantastic!</description>
		<content:encoded><![CDATA[<p>Fantastic!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Steve</title>
		<link>http://gokubi.com/archives/daily-cron-jobs-with-apex/comment-page-1#comment-23366</link>
		<dc:creator>Steve</dc:creator>
		<pubDate>Sun, 22 Apr 2007 19:12:56 +0000</pubDate>
		<guid isPermaLink="false">http://gokubi.com/archives/daily-cron-jobs-with-apex#comment-23366</guid>
		<description>Thanks for the tip Glenn. I haven&#039;t played with execution times of time-based workflow and was a bit curious. Nice to hear from someone who&#039;s looked into it a bit.</description>
		<content:encoded><![CDATA[<p>Thanks for the tip Glenn. I haven&#8217;t played with execution times of time-based workflow and was a bit curious. Nice to hear from someone who&#8217;s looked into it a bit.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Glenn Weinstein</title>
		<link>http://gokubi.com/archives/daily-cron-jobs-with-apex/comment-page-1#comment-23328</link>
		<dc:creator>Glenn Weinstein</dc:creator>
		<pubDate>Sun, 22 Apr 2007 14:09:07 +0000</pubDate>
		<guid isPermaLink="false">http://gokubi.com/archives/daily-cron-jobs-with-apex#comment-23328</guid>
		<description>A kludge to run more than 1x/day would be to change &quot;Test Script Last Run Date&quot; from a Date to a DateTime, then create multiple &quot;Batch Script&quot; objects with staggered times.  In my testing, time-based workflows will execute 24 hours after the specific DateTime, although there is typically a 5-10 minute lag between the &quot;Evaluation Date&quot; in the workflow queue (when the workflow should, theoretically, fire) and when it actually executes.  

For example:  if you want a batch job to fire every 2 hours, you could create 12 Batch Script objects, each with a Test Script Run Date 2 hours later than the last.  The practical limit would be around 10-15 minute intervals (due to the lag described above).</description>
		<content:encoded><![CDATA[<p>A kludge to run more than 1x/day would be to change &#8220;Test Script Last Run Date&#8221; from a Date to a DateTime, then create multiple &#8220;Batch Script&#8221; objects with staggered times.  In my testing, time-based workflows will execute 24 hours after the specific DateTime, although there is typically a 5-10 minute lag between the &#8220;Evaluation Date&#8221; in the workflow queue (when the workflow should, theoretically, fire) and when it actually executes.  </p>
<p>For example:  if you want a batch job to fire every 2 hours, you could create 12 Batch Script objects, each with a Test Script Run Date 2 hours later than the last.  The practical limit would be around 10-15 minute intervals (due to the lag described above).</p>
]]></content:encoded>
	</item>
</channel>
</rss>
