You need to sign in to do that
Don't have an account?
kdavis
Bulk Insert Breaks SOQL Limit
Hey guys,
So I have a trigger that will run on a bulk update or insert. My query will run 5 Aggregate queries, none of these are in for loops I query based on collected ID's. If I run for more that 2000 records and I hit
System.LimitException: Too many SOQL queries: 101. Any tips on how to work around this and bulkify my trigger more? I was thinking of batch apex but I have very little familiarity. If I use batch apex can I give a specific amount to insert at once and will it reset governor limits on every batch. Any helpful documentation on this?
Thanks.
Hello Kdavis,
Yes batch apex is the solution, for getting a better understanding please refer the following links:
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_batch.htm
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_batch_interface.htm
http://salesforcetrekbin.blogspot.in/2010/04/how-to-use-batch-apex-in-salesforce.html
All Answers
Hello Kdavis,
Yes batch apex is the solution, for getting a better understanding please refer the following links:
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_batch.htm
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_batch_interface.htm
http://salesforcetrekbin.blogspot.in/2010/04/how-to-use-batch-apex-in-salesforce.html
seems like your code has some issue.
Can you post your trigger code?
My bad, i overlooked the number of records. I agree to Avid, the batch apex is not required in this case as it is just 2000 records. We can optimize the code, please share.
So the number of records being inserted is not static, this is for a client and potentially they will be inserting/updating hundreds of thousands of records at once on one object through an integration. I know they break their inserts or updates into bulk chunks but as the number of overall records increases thats where my concern arises. Right now my trigger can handle up to around 2500 which is sufficient for them right now, I mean at best we could concise so SOQL queries but as the number of inserts increases we will still potentially hit that limit ya? I can still post the code if you guys think otherwise, but I get the feeling batch is the better long term route?