0

I'm working on a page with a very large dataset.

There is a part of the page that downloads the report as a CSV file:

<apex:outputPanel id="downloadCSVSection">
    <script>
        function downloadCSVReport()
        {
            downloadCSV('{!fileName}.csv', `{!csvFile}`);
        }
    </script>
</apex:outputPanel>

It is called by a command button:

<apex:commandButton rendered="{!DownloadButtonVisible}" status="loadingAnimation" value="{!DownloadButtonCaption}" reRender="downloadCSVSection" onComplete="downloadCSVReport();" />

and the function to generate the CSV file:

public string getCSVFile()
{
    //sorting is lost because of transient property of report, so we need to regenerate report
    // and redo sorting before saving, resort report does both
    reSortReport();
    string retString = '';
    string newLine = '\r\n';
    for(ReportHeader header:getHeaders())
    {
        retString += '"';
        retString += header.headerValue + '",';
    }
    retString = retString.removeEnd(',');
    retString += newLine;
    for(ReportRow reportRow:report)
    {
        for(ReportCell cell:reportRow.columns)
        {
            retString += cell.cellInfoEscaped + ',';
        }
        retString.removeEnd(',');
        retString += newLine;
    }
    return retString;
}

As I noted, the Report varriable is a transient variable so by my understanding of the view state it should now change at all with these chain of events, but that is not what i'm experiencing.

With very large data sets, downloading a csv of the report causes a view state exceeded error.

Using the view state monitor doesn't help as it makes it look as though the view state does not change for smaller data sets, but as soon as it reaches a certain point a view state size error is always thrown.

  • are you sure you don't have any other non-transient variables in the controller (or any custom components on the page that have non-transient variables? – cropredy May 8 at 1:29
  • There are non transient varriables in my controller, but they small things like Integers and Booleans, no large lists or anything that I feel would take a large spot in the view-state. The largest variable is probably a map<Integer,String> with 3 elements in it, and there are no non-transient variables that become bigger when the dataset gets larger – Hans Donkersloot May 8 at 14:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.