I have a Visualforce page that exports a custom CSV File. This report is very big and have a lot of processing on it thus causing sometimes CPU Limit.

The problem is that for some users always on the first attempt to export they're receiving the CPU Limit error (Log shows 0 out of 10000 Limit) but when they reload the page it exports normally.

What can this be?

Thank you!

  • 1
    First time when they try it can happen that records aint being cached takes forever and it hits CPU timeout. Once records get cached the second time it just works. – Pranay Jaiswal Apr 17 '18 at 19:08
  • @PranayJaiswal I've thought that it could be cache but my users are reporting that they don't want this behavior. To them "if it works the second time it should also work at first" and now I must have a reasonable answer for that. – Luis G. Lino Apr 17 '18 at 19:22
  • 1
    Is your query filter indexed?Is the querry selective and within the SOQL index threshold. Are you using Skinny Tables? There are so many things beneath. Can you edit and point all that you have? COde+ SOQL. It would help the community to understand the depth and give you advice accordingly. – Pranay Jaiswal Apr 17 '18 at 19:36

There's two problems: (1) the limit is a soft limit, and so may be violated if the system determines there's sufficient resources available, and (2) system load and cache can affect the effective CPU time used, causing the system to be more likely to fail during normal business hours.

Realistically, your only choice is to make this asynchronous (Queueable), which you can check the status for when it's done. You can save the CSV to an Attachment to let the users download the file. That's about all you can do.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.