I have a bunch of triggers in the opportunity object which throw System.LimitException: Apex CPU time limit exceeded when we do a mass update on opportunities. In my client org, the client has created an opportunity hierarchy by creating a lookup field to an opp and there is a query which queries to find the parent and does some calculations on the parent opportunity. I tried to do a mass update using data loader and i get an error which is the cpu time limit exceeded error. Is there an easy way to debug this on the debug log which can point me to the line of code or could you guys provide some pointers on when this error will happen on triggers? Buyan
You can use Limits.getCPUTime() from the Limits Class to monitor the execution time.
That's tricky, though. CPU time depends on how long you code is running wich means that it depends on how many records are being inserted and the debug levels that you're using. It's hard to pinpoint a location.
To avoid hitting those limits, you can try lowering the debug levels to NONE or ERROR (Adrian's suggestion) or reducing the chunk of records being updated.
If that's something to be expected, you can use the Limits class to split your code or something. Like say, if you reach 80% of the limit, instead of processing other records, just save the ids so you can make another call. Or pass them to a future method.