+ Start a Discussion

Looping Trigger.new : I have a trigger which has a for loop for each Trigger.new. It is working fine for small set of data. But, if the count is increased to 4000-5000, its throwing CPU limit exception. What is the best practice in such scenarios?

My question is, is each data load considered as one execution context or each trigger has it's own context? It would help me understand where more time is being spent. Whether time is being spent in 1. switching between multiple triggers (I know its bad practice. But, cant change so quickly now) or 2. This one trigger which is looping for 400-5000 times and creating possibly some insertions?

Due to multiple loop we get Apex CPU time limit exceeded error, do you have for loop inside for loop in your code ?, if so please remove or paste your code here to understand more.

Ajay K DubediAjay K Dubedi
Hi Jayy,
please refer the below link.


hope it'll help you, for more info please paste your code here.

Thank You.
Ajay Dubedi