4

I have seen some existing code in my org that divides lists into 1000 each in size and then use apex:repeat and apex:datatable to output them in the visualforce page, which eventually will be transferred into an excel file.

I searched about the governor limit and didn't see such a limit on list size. But obviously the original author did this on purpose. Is there something I am missing here or should I feel safe to remove such logic?

5

1 Answer 1

6

I'll post it as a answer because it would easier for other OP's to get it quickly instead of posting another duplicate question. As per standard documentation of Salesforce, the governor Limit for <apex:repeat> tag is 1000. That means you can't process list on Visualforce page having having size greater than 1000.

Maximum collection items that can be iterated in an iteration component such as <apex:pageBlockTable> and <apex:repeat> is 1000

Also for Read Only mode one can process records upto 10000

Maximum collection items that can be iterated in an iteration component such as <apex:pageBlockTable> and <apex:repeat> in read-only mode is 10000

More details about Governor limits can be found here

6
  • 1
    You can use a Map to work around this limit, as explained in this question from 2016 (almost exactly 1 year ago). It feels really hack-ish to me, but the only things limiting you with that approach are viewstate size/ CPU time/ Query rows/ Heap size limits. The only real question you'd need to ask yourself is "why do I want to display so much data at once?" Unless you're generating a csv, even 1000 records is a lot to ask for a person to visually process.
    – Derek F
    Mar 16, 2017 at 14:08
  • @DerekF That was a good answer. However OP is trying to export data into excel. So in OP's case that approach might not work. Mar 16, 2017 at 14:13
  • Why do you think it might not work? I glossed over the part where OP is eventually getting the data into Excel, but doing that by using Visualforce to generate a CSV file (which is then opened in Excel) is pretty much the only thing I think the Map approach is good for.
    – Derek F
    Mar 16, 2017 at 14:20
  • @DerekF we're bound to hit view state at some point because view state also depends on other factors. I think using Chatter to export data is good approach. Recently one of my colleague used it. I don't know how it works but I'll try that approach and post it on some other day. Mar 16, 2017 at 14:28
  • If it's just generating a CSV file, you could use the transient keyword on the map to keep it out of the viewstate (it'll still be accessible via {!myPropertyName}
    – Derek F
    Mar 16, 2017 at 14:43

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.