You need to sign in to do that
Don't have an account?
eswarsf
How to invoke a Apex class that implements Database.Batchable interface?
Hi,
I have written a Apex class hat implements Database.Batchable interface.What is the best way to call this class daily at specific time?
You can invoke this from pretty much wherever you like. The batch job gets queued for execution when the platform has resources. I've used this in the following ways:
(1) From a button clicked by a user when they want to start some heavyweight processing
(2) From the system log when I needed to update a huge amount of accounts as part of deploying some code
(3) From a scheduled apex class when cleaning up data from the previous month on the first day of the month.
All Answers
If you create another class that implements the schedulable interface, and creates/invokes the batch class, you will be able to schedule this either via the UI or other apex code.
There's an example of this in the Apex Developer's Guide at:
http://www.salesforce.com/us/developer/docs/apexcode/index_Left.htm#CSHID=apex_scheduler.htm|StartTopic=Content%2Fapex_scheduler.htm|SkinName=webhelp
Hi bob,
Thanks for your reply.In this case i could have written my code that implements Schedulable interface.Kindly let me know in which scenarios we will choose to implement Database.Batchable interface and Schedulable interface?
Generally speaking you'd use batchable when you need to process a large amount of records - i.e. more records than you can process in a single transaction. For example, something which processes all accounts in your system.
You'd use schedulable when you want an apex class to be executed at a particular time.
Thanks Bob for your reply.Generally from where we will invoke this apex class that implemented Database.Batchable interface?
You can invoke this from pretty much wherever you like. The batch job gets queued for execution when the platform has resources. I've used this in the following ways:
(1) From a button clicked by a user when they want to start some heavyweight processing
(2) From the system log when I needed to update a huge amount of accounts as part of deploying some code
(3) From a scheduled apex class when cleaning up data from the previous month on the first day of the month.
Thanks Bob.