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
supriya jain 27supriya jain 27 

Time Limit Exception/Maximum view state size limit (170KB) exceeded. when importing a csv file using visualforce page

I have created a tab for offline Dataload, where we can download the Salesforce Report (Opportunity Product), modify the downloaded csv file and click on Import button to upload the file, we are validating the csv using Apex class and display all the records below and give option to Upload/Update data in Salesforce for success Records.

Error : If we update the csv file with more than 1300 records or sometimes 1200, it fails as show Time limit exceeded error.
Is it due to csv file limit or or the record size? If Yes,Please provide us the valid limits for csv file import.

When I reduced the columns from csv file and modified the code,
Again uploaded file with 1872 -1862 records, I got error "Maximum view state size limit (170KB) exceeded. Actual view state size for this page was 170.577KB"

With 1861,1860 rows, I got
Time limit exceeded
Your request exceeded the time limit for processing.

There are two things , one is Viewstate for Visual force page and another is Time limit exception.
Another issue is that the behavior is also not stable , Sometimes it shows View state error and sometimes it works with the same number of records 
AbhishekAbhishek (Salesforce Developers) 
Hi,


Salesforce allows Visualforce pages to have a maximum view state size of 170KB.

The View State tab shows you which elements on your page are taking up that space.

A smaller view state size generally means quicker load times.
In order to avoid this error, minimize your pages' view state. You can optimize your Apex controller code and remove any superfluous Visualforce components used.

For example:

>>If you notice that a large percentage of your view state comes from objects used in controllers or controller extensions, consider refining your SOQL calls to return only data that's relevant to the Visualforce page.

>>If your view state is affected by a large component tree, try reducing the number of components your page depends on.

For your reference,

https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_tools_edit_toolbar.htm

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks.
 
hard simmhard simm
Grazie per aver condiviso il bel post. cronotermostato la funzione che consente di programmare diverse temperature di setpoint per diversi orari della giornata. Maggiori informazioni su come impostare cronotermostato qui.  https://cronotermostato.me
 
supriya jain 27supriya jain 27
Thanks Abhishek,

I checked the viewstate, but the problem is when we load more records it sometime gives "view state error" and if we reduce the rows in csv file it starts giving "Time limit exception"  and if we further reduce the rows in csv file, it works fine. So I am not able to understand, Is it the csv file size or the number of records processing while importing csv into SFDC matters.

Is there any limitations , If yes, how can I deal with it in logic without throwing exception at User's side.

User-added image
AbhishekAbhishek (Salesforce Developers) 
Hi Supriya,

Based on the Image I can see that you are facing the issue when you load more data but as mentioned it will throw an error if you upload small chunky of data.

I suspect there are some limitations to the data loader.

If you have support access you can log a case with salesforce support. I will also further check from my end and let you know if I find anything.

Thanks!

 
supriya jain 27supriya jain 27
So the major issue we are facing is Timelimit exception while processing 3k or 4k records, Is there any way to overcome this error during csv processing or should we write a batch apex to deal with, but I am afraid as Visualforce page is synchronous process and Batch Class needs to be scheduled ,

I referred this URL and tried to built some code logic,
http://developer.financialforce.com/customizations/importing-large-csv-files-via-batch-apex/

But If I want to read csv using Import button and Update data on "Load Button" Click, how should I proceed with the batch class concept for this functionality. how should we deal with the logic of fetching the csv records using CSVIterator class, handling the validation on csv file records and finally loading data in SFDC after getting success list in batch class Execute method, Basically what should be the flow for this logic using batch apex.
AbhishekAbhishek (Salesforce Developers) 
As per my knowledge, you have to change the logic 

Try this 

https://help.salesforce.com/articleView?id=000321547&type=1&mode=1

Enable developer mode in your organization, Once you will enable you to need to observe what is the source from where you are getting this view state.
You can use a transient keyword or if not required then you can remove <apex: form > with HTML form tag .which will not create view state.
Once sending to the browser if you will clear the list if any then also view stare will reduce.
If any unwanted fields are there in your list once you will remove then also you can reduce view state.

Check the below link for VF page performance.

https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_best_practices_performance.htm.