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 ?