You need to sign in to do that
Don't have an account?
Kiran kumar 193
view state error wheck click on VF page priview
Hi All,
I am getting view state error in production environment. it is working in UAT environment. PLease help me to resolve this issue.
"Maximum view state size limit (135KB) exceeded. Actual view state size for this page was 214.36KB"
VF page :
<apex:page sidebar="false" docType="html-5.0" controller="BulkUpload" showHeader="false" >
<apex:form id="form" >
<apex:sectionHeader title="Upload Carbon Data From CSV File"/>
<apex:pagemessages />
<apex:pageBlock >
<!-- Component to allow user to upload file from local machine -->
<center>
<font color="Blue"> <b>Note: Please <a href="https://drive.google.com/open?id=1BbECRGfkO1oQ5dOTyt0hbmlc9beMnfql5zpZZs" target="_blank"> Click here </a> to follow the instructions for bulkupload csv file. </b> </font> <br/>
<font color="Blue"> <b>Note: Please use the standard template to upload nova cases. <a href="https://drive.google.com/open?id=0B22fW7Nh4N5BQNTZXM" target="_blank"> Click here </a> to download the template. </b> </font> <br/>
<font color="Blue"> <b>Note: Please use the standard template to para cases. <a href="https://drive.google.com/open?id=0B22fWk1wS1Jsbms" target="_blank"> Click here </a> to download the template. </b> </font>
<br/><br/>
<apex:inputFile value="{!contentFile}" filename="{!nameFile}" />
<font color="Blue">
<apex:commandButton action="{!ReadFile}" value="Upload File" id="theButton" style="width:70px;background:green;font-weight:bold" /></font>
<!-- <br/> <br/> <font color="Blue"> <b>Note: Please use the standard template to upload cases. <a href="https://drive.google.com/file/d/0B5FQvDdE4z0PdFllT1g0aGNBN1k/view?usp=sharing" target="_blank"> Click here </a> to download the template. </b> </font>-->
</center>
<br/>
<div align="center" draggable="false" >
<apex:commandButton action="{!cancelPage}" value="Return to HomePage" styleClass="buttonStyle" style="background:green;font-weight:bold"/></div>
</apex:pageBlock>
</apex:form>
</apex:page>
Controller :
public class GAD_CarbonBulkUpload
{
transient public string nameFile{get;set;}
transient public Blob contentFile{get;set;}
transient String[] filelines = new String[]{};
List<Case> casestoupload;
// List<String> casestoupload= new List<String>();
CarbonUtility carbon = new CarbonUtility ();
transient public static Id carbonRecordtypeId = Schema.SObjectType.Case.getRecordTypeInfosByName().get('Carbon').getRecordTypeId();
public static Map<String, Carbon_Bulk_Vendor__c> Queuemap= Carbon_Bulk_Vendor__c.getAll();
/***This function reads the CSV file and inserts records into the case object. ***/
public Pagereference ReadFile()
{
try{
//Convert the uploaded file which is in BLOB format into a string
nameFile =blobToString( contentFile,'ISO-8859-1');
//Now sepatate every row of the excel file
filelines = nameFile.split('\n');
//Iterate through every line and create a Account record for each row
casestoupload = new List<Case>();
for (Integer i=1;i<filelines.size();i++)
{
transient String[] inputvalues = new String[]{};
inputvalues = filelines[i].split(',');
Case a= new Case(Status ='New', Origin = 'Web', recordtypeid = carbonRecordtypeId, isparent__c = true, Subject= 'Carbon Implementation', Business_Line__c = 'Carbon Implementation', GAD_Implementation_Type__c = 'Carbon Implementation', Effort_Hours__c=5 );
a.Customer_Id__c = inputvalues[0];
a.Features__c= inputvalues[2];
a.Language__c = inputvalues[1];
a.GAD_Vendor_Name__c = inputvalues[3];
if(a.GAD_Vendor_Name__c!= 'BoostMedia' && a.GAD_Vendor_Name__c!='Welocalize' && a.GAD_Vendor_Name__c!='Cognizant'){
system.debug('enter into if loop'+ a.GAD_Vendor_Name__c);
carbon.setCaseAssignment(a);
}
if(Queuemap !=null && Queuemap.containsKey(a.GAD_Vendor_Name__c)){
a.ownerid = Queuemap.get(a.GAD_Vendor_Name__c).Queue_id__c;
}
a.Name__c = inputvalues[4];
a.Email__c= inputvalues[5];
a.Team__c= inputvalues[6];
a.Manager__c= inputvalues[7];
a.Manager_Email__c= inputvalues[8];
a.Location__c= inputvalues[9];
a.LDAP__c= inputvalues[10];
a.Agency__c = inputvalues[11];
a.Name1__c= inputvalues[12];
a.AgeEmail__c= inputvalues[13];
casestoupload.add(a);
}
}
catch(Exception e){
ApexPages.Message errormsg = new ApexPages.Message(ApexPages.severity.ERROR,'An error has occured reading the CSV file'+e.getMessage());
ApexPages.addMessage(errormsg);
}
/* for(Case c1:casestoupload){
casestoupload.addall(carbon.setCaseAssignment(c1));
} */
//Finally, insert the collected records
try{
insert casestoupload;
if(casestoupload.size()>0)
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.confirm,'Upload has been successful and cases has been created successfully'));
}
catch (Exception e)
{
ApexPages.Message errormsg = new ApexPages.Message(ApexPages.severity.ERROR,'An error has occured inserting the records'+e.getMessage());
ApexPages.addMessage(errormsg);
}
return null;
}
/**** This function sends back to the visualforce page the list of account records that were inserted ****/
/*public List<Case> getuploadedAccounts()
{
if (casestoupload!= NULL)
if (casestoupload.size() > 0)
return casestoupload;
else
return null;
else
return null;
} */
/**
This function convers the input CSV file in BLOB format into a string
@param input Blob data representing correct string in @inCharset encoding
@param inCharset encoding of the Blob data (for example 'ISO 8859-1')
*/
public static String blobToString(Blob input, String inCharset){
String hex = EncodingUtil.convertToHex(input);
System.assertEquals(0, hex.length() & 1);
final Integer bytesCount = hex.length() >> 1;
String[] bytes = new String[bytesCount];
for(Integer i = 0; i < bytesCount; ++i)
bytes[i] = hex.mid(i << 1, 2);
return EncodingUtil.urlDecode('%' + String.join(bytes, '%'), inCharset);
}
public pagereference cancelPage(){
Pagereference pageRef = new Pagereference('/apex/HomePage');
return pageRef;
}
}
I am getting view state error in production environment. it is working in UAT environment. PLease help me to resolve this issue.
"Maximum view state size limit (135KB) exceeded. Actual view state size for this page was 214.36KB"
VF page :
<apex:page sidebar="false" docType="html-5.0" controller="BulkUpload" showHeader="false" >
<apex:form id="form" >
<apex:sectionHeader title="Upload Carbon Data From CSV File"/>
<apex:pagemessages />
<apex:pageBlock >
<!-- Component to allow user to upload file from local machine -->
<center>
<font color="Blue"> <b>Note: Please <a href="https://drive.google.com/open?id=1BbECRGfkO1oQ5dOTyt0hbmlc9beMnfql5zpZZs" target="_blank"> Click here </a> to follow the instructions for bulkupload csv file. </b> </font> <br/>
<font color="Blue"> <b>Note: Please use the standard template to upload nova cases. <a href="https://drive.google.com/open?id=0B22fW7Nh4N5BQNTZXM" target="_blank"> Click here </a> to download the template. </b> </font> <br/>
<font color="Blue"> <b>Note: Please use the standard template to para cases. <a href="https://drive.google.com/open?id=0B22fWk1wS1Jsbms" target="_blank"> Click here </a> to download the template. </b> </font>
<br/><br/>
<apex:inputFile value="{!contentFile}" filename="{!nameFile}" />
<font color="Blue">
<apex:commandButton action="{!ReadFile}" value="Upload File" id="theButton" style="width:70px;background:green;font-weight:bold" /></font>
<!-- <br/> <br/> <font color="Blue"> <b>Note: Please use the standard template to upload cases. <a href="https://drive.google.com/file/d/0B5FQvDdE4z0PdFllT1g0aGNBN1k/view?usp=sharing" target="_blank"> Click here </a> to download the template. </b> </font>-->
</center>
<br/>
<div align="center" draggable="false" >
<apex:commandButton action="{!cancelPage}" value="Return to HomePage" styleClass="buttonStyle" style="background:green;font-weight:bold"/></div>
</apex:pageBlock>
</apex:form>
</apex:page>
Controller :
public class GAD_CarbonBulkUpload
{
transient public string nameFile{get;set;}
transient public Blob contentFile{get;set;}
transient String[] filelines = new String[]{};
List<Case> casestoupload;
// List<String> casestoupload= new List<String>();
CarbonUtility carbon = new CarbonUtility ();
transient public static Id carbonRecordtypeId = Schema.SObjectType.Case.getRecordTypeInfosByName().get('Carbon').getRecordTypeId();
public static Map<String, Carbon_Bulk_Vendor__c> Queuemap= Carbon_Bulk_Vendor__c.getAll();
/***This function reads the CSV file and inserts records into the case object. ***/
public Pagereference ReadFile()
{
try{
//Convert the uploaded file which is in BLOB format into a string
nameFile =blobToString( contentFile,'ISO-8859-1');
//Now sepatate every row of the excel file
filelines = nameFile.split('\n');
//Iterate through every line and create a Account record for each row
casestoupload = new List<Case>();
for (Integer i=1;i<filelines.size();i++)
{
transient String[] inputvalues = new String[]{};
inputvalues = filelines[i].split(',');
Case a= new Case(Status ='New', Origin = 'Web', recordtypeid = carbonRecordtypeId, isparent__c = true, Subject= 'Carbon Implementation', Business_Line__c = 'Carbon Implementation', GAD_Implementation_Type__c = 'Carbon Implementation', Effort_Hours__c=5 );
a.Customer_Id__c = inputvalues[0];
a.Features__c= inputvalues[2];
a.Language__c = inputvalues[1];
a.GAD_Vendor_Name__c = inputvalues[3];
if(a.GAD_Vendor_Name__c!= 'BoostMedia' && a.GAD_Vendor_Name__c!='Welocalize' && a.GAD_Vendor_Name__c!='Cognizant'){
system.debug('enter into if loop'+ a.GAD_Vendor_Name__c);
carbon.setCaseAssignment(a);
}
if(Queuemap !=null && Queuemap.containsKey(a.GAD_Vendor_Name__c)){
a.ownerid = Queuemap.get(a.GAD_Vendor_Name__c).Queue_id__c;
}
a.Name__c = inputvalues[4];
a.Email__c= inputvalues[5];
a.Team__c= inputvalues[6];
a.Manager__c= inputvalues[7];
a.Manager_Email__c= inputvalues[8];
a.Location__c= inputvalues[9];
a.LDAP__c= inputvalues[10];
a.Agency__c = inputvalues[11];
a.Name1__c= inputvalues[12];
a.AgeEmail__c= inputvalues[13];
casestoupload.add(a);
}
}
catch(Exception e){
ApexPages.Message errormsg = new ApexPages.Message(ApexPages.severity.ERROR,'An error has occured reading the CSV file'+e.getMessage());
ApexPages.addMessage(errormsg);
}
/* for(Case c1:casestoupload){
casestoupload.addall(carbon.setCaseAssignment(c1));
} */
//Finally, insert the collected records
try{
insert casestoupload;
if(casestoupload.size()>0)
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.confirm,'Upload has been successful and cases has been created successfully'));
}
catch (Exception e)
{
ApexPages.Message errormsg = new ApexPages.Message(ApexPages.severity.ERROR,'An error has occured inserting the records'+e.getMessage());
ApexPages.addMessage(errormsg);
}
return null;
}
/**** This function sends back to the visualforce page the list of account records that were inserted ****/
/*public List<Case> getuploadedAccounts()
{
if (casestoupload!= NULL)
if (casestoupload.size() > 0)
return casestoupload;
else
return null;
else
return null;
} */
/**
This function convers the input CSV file in BLOB format into a string
@param input Blob data representing correct string in @inCharset encoding
@param inCharset encoding of the Blob data (for example 'ISO 8859-1')
*/
public static String blobToString(Blob input, String inCharset){
String hex = EncodingUtil.convertToHex(input);
System.assertEquals(0, hex.length() & 1);
final Integer bytesCount = hex.length() >> 1;
String[] bytes = new String[bytesCount];
for(Integer i = 0; i < bytesCount; ++i)
bytes[i] = hex.mid(i << 1, 2);
return EncodingUtil.urlDecode('%' + String.join(bytes, '%'), inCharset);
}
public pagereference cancelPage(){
Pagereference pageRef = new Pagereference('/apex/HomePage');
return pageRef;
}
}
Remove docType="html-5.0" in vf page and try once.
Let me know if any further issue.
Thanks,
Regards,
naga.