+ Start a Discussion

Updating Bulk data and causing Too many SOQL error

  • I am updating List of custom object through apex.
  • This causes multiple triggers to fire for same object and related object.
  • These triggers have SOQL quries.
  • If List is having 1000 records, then it fails in between due to error " Too Many SOQL" .
  • This is due to Trigger calls multiple times. For 1000 records it will call 5 times as 200 records in one execution. while doing this it counts number of SOQL quries and hits more than 100.

Please let me know my Solution is right or wrong :- one update starts one transaction in SFDC, so for 1000 records a trigger will fire 5 times (200 records in a batch) This causes SOQL Limit to hit easily. TO overcome this, I am splitting 1000 list of records into small list of 200 records so i will have 5 list with me. Now I am firing update statement in the loop for 5 times, so that i can process my whole data. Small list count 200 * 150 update statement = 30000 records I can process without any error.


Please let me know this approach is fine or not.


Does your trigger(s) has any code with SELECT/UPDATE statements in FOR loop? If so what ever might be the count, I would recommend to remove them from the loop

NO Update statement is not in for...

But there are nesting of triggers. when webservive makes update then it fires multiple triggers.

so if i fire multiple update statements (less then 150) then i can able to update lot of data.

but it will work only when --> each DML will start new transaction...


Please let me know your reply on this...