+ Start a Discussion
kdaviskdavis 

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.

Best Answer chosen by Admin (Salesforce Developers) 

All Answers

Avidev9Avidev9
Batch apex is definitely not a replacement of a trigger.
seems like your code has some issue.
Can you post your trigger code?
Vinita_SFDCVinita_SFDC

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.

kdaviskdavis

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?