You need to sign in to do that
Don't have an account?
Force.com
Help needed in Batch apex
After running a Batch script, a New Apex job gets created. So Whenever I run the batch again, it throws an exception saying:
"The Apex job named "New Job" is already scheduled for execution".
then I delete the existing Apex job from Setup -> Monitoring -> Scheduled jobs to resolve the exception.
I need to delete the existing apex jobs automatically once they are completed.
Are there any possible workarounds for this?
Plz help, its urgent
You could hold on to the ids of the scheduled jobs and pass them into a System.abortJob call before scheduling your new jobs.
System.abortJob(jobId)
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_system.htm
Thanks for reply.
In the finish method I tried to abort the apex scheduled job but the next time whenevr I run the batch, previous job still exists in the database.
How shall I get the existing jobIds?
Hello,
I would like to tell, that Schedulars and Batches are different concepts.
there Batch can be scheduled only once, but it can be called multiple times.
I think instead of Executing batch you are Executing Schedular.
Let me know if you dont get it.
Thanks
Hi ALL i am running thru same issue.. My requirement is to run the batch every 15 mins and i ger error all the time that my
The Apex job named "Schedule Job1" is already scheduled for execution."
Below is my code.
thanks
Hi symantecAP,
I also faced the same problem. I tried to delete the Scheduled jobs programmatically but it is not supported through apex. So each time I made a call, I called the Schedulable Batch Class with a different Apex Job name. I tried to change the name of the Apex Job dynamically. Code snippet is:
All the finished Scheduled Jobs are deleted automatically after a certain period of time.
Please try the above workaround. I hope it will help.
Thanks,
Pragati
Hi Pragati
Thank you so much for the reply. If I understand it clearly this code snippet is to schedule the class every minute?
How do I dynamically change the Apex job name and lets say once they get killed, can they be restarted? coz it has to run every 15 mins round the clock .
ANd how would it kill the job without system.abort ( jobid)
Thanks
Adil
Hi symantecAP,
I scheduled the batch for every minute. You can schedule it to run after every 15minutes with different job name. Each time you make a call to Batch, a new Apex job will be created.
I tried to kill the job using system.abort ( jobid). But still I could see the Job exists in the Schedule Jobs List. That was the reason I created new Job with different name in every minute through code.
I don't exactly remember now but somewhere it was written in the documentation that Apex jobs automatically get deleted after 20 days(Not sure) from the Schedule Jobs List in the Setup.
Thanks,
Pragati
Hi Pragati
I understood the trick , This is awsome so far.. I scheduled it now. Its scheduled every min. will let you know if i run in to some errors.. U r a saviour