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
Nicolás KacowiczNicolás Kacowicz 

State Size limit (135KB) and Apex CPU time limit exceeded

Hello, I'm getting both of these errors.
I'm trying to upload Accounts through a CSV file from a Visualforce Page. The csv file is 300kb.
I have a for that reads the csv file, and then I use Database.upsert.

I got both the Apex Class and the VF Page from http://www.forcetree.com/2010/08/read-and-insert-records-from-csv-file.html.

I just customized to my needs, mostly the Apex Class. 
This is the Visualforce Page:

<apex:page sidebar="false" controller="FileUploaderAccountTotal" showHeader="false">
    <apex:form >
        <apex:sectionHeader title="Upload data from CSV file"/>
        <apex:pagemessages />
        <apex:pageBlock >
            <!--  Component to allow user to upload file from local machine -->
            <center>
                <apex:inputFile value="{!contentFile}" filename="{!nameFile}" /> <apex:commandButton action="{!ReadFile}" value="Upload File" id="theButton" style="width:70px;"/>
            </center>  
            
            <!-- After the user clicks the 'Upload File' button, this section displays the inserted data -->
            
            <apex:pageblocktable value="{!uploadedAccountsTotal}" var="con" rendered="{!NOT(ISNULL(uploadedAccountsTotal))}">
                <apex:column headerValue="Name">
                    <apex:outputField value="{!con.Name}"/>
                </apex:column>
                <apex:column headerValue="Sponsor">
                    <apex:outputField value="{!con.Sponsor__c}"/>
                </apex:column>
                <apex:column headerValue="Areas">
                    <apex:outputField value="{!con.Areas__c}"/>
                </apex:column>
            </apex:pageblocktable>            
            
        </apex:pageBlock>       
    </apex:form>   
</apex:page>

I even tried to put public transient Blob contentFile{get;set;} with the transient but it didn't matter. I need to be able to upload a file larger than that.

For the CPU time I don't understand what I'm doing wrong, I have this big for with no query inside and then after an upload I have a for of the same size that inserts some Lookup IDs needed to the Object.

Thanks!