+ Start a Discussion
Aimee SkiddsAimee Skidds 

Apex CPU time limit exceeded error

We are getting an error when we try to change a custom object field. This custom object (Projects) has Apex triggers that affect Opportunities associated with it (there are roughly 380 Opportunities associated with this object). The error is this:

There were custom validation error(s) encountered while saving the affected record(s). The first validation error encountered was "Apex trigger Publication caused an unexpected exception, contact your administrator: Publication: execution of AfterUpdate caused by: System.LimitException: Apex CPU time limit exceeded: Trigger.Publication: line 316, column 1".

On the day that we started receiving this error, we changed our calendar year to a fiscal year (7/1-6/30) and also added a rollup in the Opportunity based on this new fiscal year.

Any ideas?
SFDC HedgehogSFDC Hedgehog
Hi Aimee

Did you try putting your apex trigger work that is crashing on this limit into an "@future" context?
Caveat:   If you are depending on "instant data update" you will be out of luck - it can take awhile to get 380 opportunities updated.... You will probably have to manage some user-expectations if this is the case.

 
Amit Chaudhary 8Amit Chaudhary 8
I hope in Trigger.Publication trigger you are using loop inside the for loop.
The Maximum CPU time on the salesforce servers - 10,000 milliseconds (Synchronous limit) 60,000 milliseconds(Asynchronous limit).

Please check below post to resolved this issue
http://salesforce.stackexchange.com/questions/22223/how-to-code-more-efficient-to-avoid-apex-cpu-time-limit-exceeded
http://salesforce.stackexchange.com/questions/47035/errorsystem-limitexception-apex-cpu-time-limit-exceeded

Please let us know if this will help you

Thanks
AMit Chaudhary