function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Sai LaasyaSai Laasya 

apex page attribute readOnly

Hi,

I am using a vf page for downloading a list of records on button click as an excel sheet. To enable more than 1000 records, I have added readOnly="true" for the vf page. But the attribute doesn't seem to work. Is there anything else I have to do to overcome "Collection too large" error. Please help.
Waqar Hussain SFWaqar Hussain SF
<apex:commandButton disabled="{!isButtonDisabled}

//Get isButtonDisabled from controller

use above code, don't use readOnly="true"
srlawr uksrlawr uk
Hi Sai,

Could you post a little bit of your controller and visualfore page? I can assure you that "readOnly" works as intended generally speaking, so there must be some nuance with your work that is causing it to bug out! We can't begin to speculate without seeing how your page works though :)
Sai LaasyaSai Laasya
I am using 2 vf pages and one controller. The first vf page contains an Export button
 
<apex:commandbutton value="Export" action="{!Export}" />

On clicking which an export method is called from the controller.
 
    public PageReference Export(){
        Pagereference pref = new Pagereference('/apex/ExportToExcel'); 
        return pref; 
    }
    
    public void ExporttoExcel(){
        lstpri = new List<Item__c>();
        lstpri = QueryItems();
    }

I have pasted below the <apex:page> tag from my second vf page which is actually throwing the error
 
<apex:page controller="ItemUpdate" action="{!ExportToExcel}" contentType="application/vnd.ms-excel#Filtered Price Records.xls" readOnly="true">


Note: the QueryItems() method returns a list of records whose size exceeds 1000.
srlawr uksrlawr uk
Do you have readOnly on the first page (that has the button on it)?

That method on line 6, is on the first page - with the button? That also needs to be read only if you want the list "lstpri" to contain > 1000 items.
Sai LaasyaSai Laasya
I have placed readOnly="true" in both the pages. But, still I am getting the same error.
srlawr uksrlawr uk
if you take the contentType flag off the second page, and just render it as a page - does it work? That would be a potential pitfall to me, so I would try to test that...