+ Start a Discussion
DManelskiDManelski 

Question about batch apex & governor limits

I'm considering writing a batch cloning operation for opportunities.  I'm concerned that I'm going to bump up against governor limits, here's why:

 

I have quite a few triggers that fire on the creation of new opps.  They're all bulkified but I still run into heap size limits and occasionally SOQL rows when inserting (or updating) batches of opportunities greater than 40-50 through the API (DataLoader, DemandTools, etc.). 

 

As I understand it, batch apex won't let me work with batches smaller than 200, so my question is, will I run into the same heap size limits or SOQL rows in batch apex? When my DML is executed for my batch(es), and in turn fires triggers, are those triggers operating with trigger governor limits for this transaction, or within the higher batch apex governor limits?

Message Edited by DManelski on 08-26-2009 11:20 AM
pbulaczpbulacz

I believe you can set the batch size when firing Batchable.Execute();

 

It takes 2 parameters. 

 

• The class that implements Database.Batchable.
• The number of records to be passed as a single chunk to the execute method. This value must be greater than 0 and less
than 200. Use this when you have many operations for each record being passed in and are running into governor limits.
By limiting the number of records, you are thereby limiting the operations per transaction.

 

Straight from the lang ref... However I'm trying to implement this myself currently.

 

Current example I have 5000+ records that get queried.. for each of those 5000 I need to create a new record in another object and insert it.

 

However similar to you I have triggers firing off of the object being inserted so I run into some script statement and heap size limits. So I figured I'd be able to just do Batchable.Execute(Class,50);  To run my batch class in chunks of 50 as I know that 50 will work everytime.

 

My debug logs show "Operation Batch Apex" Success....  and nothing else!

 

And my Apex Jobs log shows"total batches = 0, batches processed = 0, failures = 0, status = completed"

 

I'm at a loss so any help would be great!

SOQL locator query with 5705 rows finished in 935 ms

Cumulative resource usage:

Total email recipients queued to be sent : 0
Stack frame variables and sizes: