Would using the loadAllRemainingRecords() cause Apex Heap Errors?

  • 1
  • Question
  • Updated 2 years ago
  • Answered
I've found the loadAllRemainingRecords() method to be quite handy. I'm now wondering if we need to worry about Apex Heap Limits when using this...

Say for example, if we run a snippet that calls this function against a handful of models when a tab in the page is first show/whenever shown. That can be very handy to load the rest of the related records not shown, but....do we need to worry about getting the Apex Heap Errors when using this on a page??

Thanks for any answers!

-Jeff
Photo of Jeff Rutter

Jeff Rutter

  • 1,162 Points 1k badge 2x thumb

Posted 2 years ago

  • 1
Photo of Mark DeSimone

Mark DeSimone, Official Rep

  • 11,040 Points 10k badge 2x thumb
Hi Jeff, it's smart of you to be thinking ahead about this, especially when you're going beyond the boundaries of Declarative solutions. I think the main considerations are generally going to boil down to these:

1) how many records total will be queried? How wide is the rectangle?
2) how many fields in each model will be queried? - How tall is the rectangle?
3) how many models will be queried, and are they being queried simultaneously? - How many rectangles are there?

Of course, you'd want to do what you can to keep all of these values reigned in. In your scenario, you might also consider whether or not you can stagger your use of loadAllRemainingRecords() so it's not querying multiple models at the same time. The Skuid Page Performance Guide is helpful for anyone who's trying to fine-tune their pages, and goes into much more detail about this. Using the lazy load settings where available, as well as page includes where applicable, can help you compartmentalize queries too, so they don't all request data right on page load. 
Photo of Jeff Rutter

Jeff Rutter

  • 1,162 Points 1k badge 2x thumb
Hi Mark,

Thanks for the feedback. The Skuid Page Performance Guide was a good reminder too; I'll keep that in my back pocket.

I can see with our current build using this on multiple models could become an issue. Sounds like something we should load test and will consider your questions as well. 

Thanks for the help! 

-Jeff