3

I have a simple Apex Class, method execute() which reads every 5000 (Queries everytime for next 5000 leads) leads and applies business rules and update 200 at a time. but we have triggers on the Lead obj, so every update its increasing the limit and reaching the governor limit. Its not resetting for every execute or Database.update(). can you please let me know, Is there a way I can reset the transaction to start over the governor limits. Appreciate your help!

10

Use batch Apex as described e.g. Force.com Batch Apex and Large Data Volumes. This allows work over a large number of SObjects (or other objects) to be executed in batches where each execute method has its own set of governor limits.

Added after nvr's first comment:

You can run a sequence of batch Apex jobs - a chain - by starting a new job in the finish method of the current job (and so on). Typically, as well as implementing the Database.Batchable interface, you will also add the Database.Stateful marker interface so you can preserve state and forward it to the next batchable in the chain. This approach allows the jobs to be run one after another and so avoids hitting the concurrent jobs governor limit.

Do note though that batch jobs are queued and the processing delays and processing rate are at salesforce's discretion: progress may be slower than you expect.

  • That's what I was going to say, but with an example. I'd recommend updating this answer with more info than just a link. – sfdcfox Nov 4 '13 at 20:43
  • I am looking for a solution without batch, since it has limit for 5 jobs can only run concurrently. We have a huge set of jobs that needs to be run in SFDC , so cameup with a JavaApplication with Schduler to make a call to Apex Webservice and access the class to complete the job, with in Apex class method , I need to query for input data and apply business rules and then do an update of those records. Can anybody please help me with a solution to acheive with out batch Apex. – nvr Nov 4 '13 at 20:45
  • 3
    Suggest you update the question to be more specific then. Also Google about job chaining where the finish of one job starts the next. – Keith C Nov 4 '13 at 20:49
  • sfdcfox - I added a tiny bit more to the answer as I understand the aim here is to not just provide links... – Keith C Nov 4 '13 at 20:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.