unknown issue causing "APEX CPU time limit exceeded"

  • 2
  • Problem
  • Updated 5 months ago
  • In Progress
Photo of mB Pat Vachon

mB Pat Vachon, Champion

  • 42,714 Points 20k badge 2x thumb

Posted 2 years ago

  • 2
Photo of Barry Schnell

Barry Schnell, Champion

  • 18,076 Points 10k badge 2x thumb
Pat -

If you're not familiar with Salesforce Governors, I'd recommend first reading up on them starting with https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_gov_limits.htm.

The intermittent nature of what you are seeing can be explained by the not to obvious fact that SFDC states that they have the "right to kill" your process if you exceed a governor.  The key word is "right" - note that it doesn't say they "will."  In short, if an execution context exceeds one of the governors, sometimes SFDC will kill your request and sometimes it won't.  There's no docs as to when they will or when they won't unfortunately.  That said, if the load on your instance is low enough at the time of the request SFDC will likely let things run a little longer than the governor allows for.  When load is higher, they will likely kill the request as soon as you exceed the limit.  In short, this is more than likely why sometimes things work and sometimes they don't.

Another possibility are due to other factors that come in to play regarding CPU usage keeping in mind that the same exact request will always vary a little bit with regards to the amount of CPU time required.  It is possible that your current config is right on the border line of the max CPU and so sometimes things run a bit faster and the request succeeds while other times, things run a bit slower and the request fails.

As for why the page is taking a long time, I'd recommend using the developer console and setting up DEBUG tracing to try to determine where the request is spending the bulk of its time to start to isolate the root cause.
(Edited)
Photo of Shmuel Kamensky

Shmuel Kamensky, Champion

  • 4,328 Points 4k badge 2x thumb
It's far out, but skuid makes API calls to Salesforce. It's worth checking to see if your API request limit has been reached. You can check it in the System Overview section. 
Photo of mB Pat Vachon

mB Pat Vachon, Champion

  • 42,714 Points 20k badge 2x thumb
Photo of Shmuel Kamensky

Shmuel Kamensky, Champion

  • 4,328 Points 4k badge 2x thumb
Can you post the debug log that showed the 30 second query somewhere?
Photo of mB Pat Vachon

mB Pat Vachon, Champion

  • 42,714 Points 20k badge 2x thumb
Strange. I had posted something earlier with that.

Here it is.

https://docs.google.com/spreadsheets/...
Photo of Shmuel Kamensky

Shmuel Kamensky, Champion

  • 4,328 Points 4k badge 2x thumb
I see. You do query lots of relationships going three levels deep in one of them. I think CreatedBy and LastModifedBy are polymorphic relationships since they could be groups or users. But like you said that shouldn't be the issue since it's working when you remove the where condition.

 Some possible contributors to the issue:
Photo of Karen Waldschmitt

Karen Waldschmitt, Official Rep

  • 8,240 Points 5k badge 2x thumb
Pat~

Wanted to check in and see if you're still having this issue. 

Thanks!
Karen
Photo of mB Pat Vachon

mB Pat Vachon, Champion

  • 42,714 Points 20k badge 2x thumb
Yup. Spot on. The queries being built were asking for a record each and approx. 25-50 fields each. So really not something for SF to trip up on.
Photo of Rick Nendza

Rick Nendza

  • 110 Points 100 badge 2x thumb
I encountered the cpu limit on various queries that returned only 1 row as well. For us. it wasn't so much the nbr of rows returned but rather the looping that was building the soql as we were doing describe calls and then evaluating each field deciding whether or not to put it in the SOQL string.
Photo of Shmuel Kamensky

Shmuel Kamensky, Champion

  • 4,328 Points 4k badge 2x thumb
Rick, depending on how the SOQL is implemented, it's possible that it could eat away at your CPU limits. E.g. if you did a Database.QueryLocator 
Photo of Rick Nendza

Rick Nendza

  • 110 Points 100 badge 2x thumb
We did not. It's a simple 1 row result / real time query not used in Batch Apex but rather a controller backing a VF Page.
Photo of Shmuel Kamensky

Shmuel Kamensky, Champion

  • 4,328 Points 4k badge 2x thumb
I think Database.query can also give a CPU timeout exception. Is that how skuid runs queries? Or do they have some other system for dynamic query strings?
Photo of Karen Waldschmitt

Karen Waldschmitt, Official Rep

  • 8,240 Points 5k badge 2x thumb
Hi community~

We tried to contact Salesforce about getting more details about what happened with NA43. Here's what we heard back: 

If you need more information outside of what is posted to TRUST, you'll have to log a case to make a formal request.

At this time, Salesforce only sends proactive alerts for system incidents to our premier customers / partners.  
All other customers should proactively use TRUST to check for incidents when issues are noticed, or use the RSS function on instances to setup a RSS feed for status updates when they are posted.

Sorry couldn't help shed more light on what happened but hopefully you can do one of the suggestions above to learn more about things as they affect you ...
Karen
Photo of Rick Nendza

Rick Nendza

  • 110 Points 100 badge 2x thumb
Thank you so much for trying! Typical of SFDC.. Unfortunately my clients do not pay the bucho $$$ for premier support. Any case we submit with any substance ultimately gets thrown back at us telling us to pay the man. lol. Anyway, thanks so much for trying! Maybe others with premier support can share the wealth. :)
Photo of Jack Sanford

Jack Sanford, Champion

  • 8,322 Points 5k badge 2x thumb
I'm having this issue across the board with a large page that is not even querying any models upon page load since Salesforce updated to Summer '18 on NA38. Anyone else having this issue?
Photo of Stephen Sells

Stephen Sells, Official Rep

  • 16,856 Points 10k badge 2x thumb
Are you able to reduce the size of the page via page includes or anything?