Here is what I'm trying to achieve:
- Upload a csv file on the click of "Upload File" button. ReadFile() method is invoked
- On click of "Action" button, all the row data will be uploaded to a custom object. Processing() method is invoked (not included in the code below, but it uses "emailList" List).
Here's the code for my controller class:
public class FileUploaderTest {
public transient string nameFile {get;set;}
public transient blob contentFile {get;set;}
public transient string[] fileLines = new string[]{};
public List<string> emailList = new List<string>();
public static String blobToString(blob input, String inCharset){
//code to convert blob to string.
}
public Pagereference ReadFile(){
nameFile =blobToString(contentFile,'ISO-8859-1');
filelines = nameFile.split('\n');
for (Integer i=0;i<filelines.size();i++)
{
emailList.add(filelines[i]);
}
return null;
}
public Pagereference processing(){
//Uses emailList List and logic is performed based on the elements of this list.
}
Everything is working as expected but I'll be facing the issue when the csv file is large. This is because "emailList" is a part of view state. I cannot make emailList transient because I'm getting null pointer exception error. I tried making it static but oddly, no data comes into the list and the list appears to be empty.
So is there is any way I can exclude emailList from viewstate? Or, is it possible to make a copy of it within the class and clear emailList in ReadFile() itself to clear the viewstate?