function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

Looping : I have a trigger which has a for loop for each 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