1

Context

Since Lightning component Aura or LWC does not support @ReadOnly mode yet, we have opted for a Visualforce page to export queried data into an Excel and benefit from higher query rows limit.

As per documentation, collection size limit is increased from 1,000 to 10,000 in readonly mode.

In addition to querying many more rows, the readOnly attribute also increases the maximum number of items in a collection that can be iterated over using components such as <apex:dataTable>, <apex:dataList>, and <apex:repeat>. This limit increased from 1,000 items to 10,000.

Although documentation mentions collection, we have noticed that this limit seems to apply for List but not for Map.

Here are some sample code to illustrate the behavior between List and Map.

Apex class

public with sharing class VFC_Collection{
    public Map<Integer, String> mapResult { get; set; }
    public List<String> listResult { get; set; }

    public VFC_Collection(){
        mapResult =new Map<Integer, String>();
        listResult =new List<String>();

        for (Integer i = 0; i < 20000; i++){
            mapResult.put(i, 'Row'+i);
            listResult.add('Row'+i);
        }

    }    
}

VF using list - Fails with error: Collection size 20,000 exceeds maximum size of 10,000.

<apex:page controller="VFC_Collection" readOnly="true" >    
    <apex:repeat value="{!listResult }" var="i">
        <p> {!i}</p>
    </apex:repeat>                    
</apex:page>

VF using map : Successful, Page displays all 20000 lines

<apex:page controller="VFC_Collection" readOnly="true" >           
    <apex:repeat value="{!mapResult }" var="i">
        <p> {!mapResult[i]}</p>
    </apex:repeat>                          
</apex:page>

In the case of the map, the number of iterations could be increased above 20,000 if other limits CPU ou Heap size are not exceeded before that.

Questions:

  • does this means that a map can contain more data than a list in readonly mode or in general ?
  • is there any known limit for max number of items a map can be iterated over in ReadOnly mode ?
  • in readOnly mode, any risk that adding more an 10,000 in a map can break in the future ?
2

The only practical limits to how much you can display are Heap Size and CPU Time, as I answered here. I was able to populate a Map with over one million records and Visualforce allowed the collection to render.

As for your other questions, there is no real difference between storage capacity for Map vs. List, other than how much memory they consume. I would consider the risk that this behavior might change in the future to be very near zero, as Salesforce is not investing heavily in Visualforce any more.

| improve this answer | |
1

Despite not working as documented, you should not depend on this behavior working forever. Even though it's working now, it would surely have a significant performance penalty as compared to using more modern methods. It would be better to work on proper pagination using either an API or creative querying. For example, in Lightning, you can query 50,000 rows at a time without an issue, and you could use WHERE Id > :lastId ORDER BY Id ASC. I went in to more detail here.

It's quite possible to query many millions of records in time comparable to what it would take in the API, without any limits at all, other than what your browser/client is able to handle in memory. You could also do this in Visualforce with @RemoteAction methods for improved performance over Visualforce rendering. Also, there's a hard limit of 15,000,000 bytes for a rendered page, so doing this will drastically improve performance.

| improve this answer | |
  • Thanks, got your point but we are not displaying the records on the page; in our use case, the data needs to be exported in Excel on page load hence the choice of VF. The examples in the question were meant to show difference between list and map. Also, its several SOQL results which must be grouped into a single export and we do have some limits on the queries. Std report does not meet the requirement because data model is too complex – Shamina Apr 14 at 18:51
  • @Shamina You can implement "export to Excel/CSV" with a Data URI, and you can perform an unlimited number of queries using client-side JS. I'm just saying you shouldn't necessarily tie yourself down to just using Apex, other possibilities exist. – sfdcfox Apr 14 at 18:57
  • Yes we did try other option of using lightning component/client side JS but experienced browser slowness and high consumption of the computer resources. – Shamina Apr 14 at 19:03

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.