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
Mit PatelMit Patel 

Maximum view state size limit (135KB) exceeded

Hi,

 

I am creating an application and i am getting "Maximum view state size limit (135KB) exceeded" error. Actually i am displaying record in tabular form and i am getting more 10,000 record from database. I have mentioned variables as a transient and but still i am facing same problem. Can you please tell me is there any other option to recover from that problem.

 

Thanks,

Mitul


Srikant JoshiSrikant Joshi

Hi,

 

Strange you used Transient and it still didn't work.

 

Can you show it through the code?

 

 

Mit PatelMit Patel

Hello Srikant,

Thanks for ther reply.....

 

below i pasted the method code where i am using some class level variable that i declared as transient but i dint mention transient with those field that used to save record in database.

 

Class level field are - 

public transient boolean showLeasingBackPageLink {get;set;}
public transient boolean showLeasingForwardPageLink {get;set;}

public transient String selectedPeriod{get;set;}

public transient Boolean showLeasingPageLabel {get;set;}

private transient String leasingQuery;

public transient String queryCondition{get;set;}

 

-------------------------------------------------Method Code where i am getting error----------------------------------------------------------------

public void  searchHistory() {
queryCondition='';
leasing.clear();
allLeasing.clear();
leasingQuery = '';
 //COLLECTING ALL THE PROPERTY ID'S SELECTED BY THE USER FOR FILTER
String propertyIdsSelectedFromLeasingActTab = '';
for(PropertyWrapperClass prop : propertyWrapper){
if(prop.isSelected){
 propertyIdsSelectedFromLeasingActTab += '\'' + prop.PropertyList.Id + '\',';
}
}
if(propertyIdsSelectedFromLeasingActTab.length() > 1) {
propertyIdsSelectedFromLeasingActTab = propertyIdsSelectedFromLeasingActTab.substring(0, propertyIdsSelectedFromLeasingActTab.length()-1);
//System.debug('propertyIdsSelectedFromLeasingActTab: '+propertyIdsSelectedFromLeasingActTab);
queryCondition = 'Where Target_List__r.Property__c IN (' + propertyIdsSelectedFromLeasingActTab + ') ';
}
 String targetIdsSelectedFromLeasingActTab = '';
for(TargetListWrapperClass trg : targetWrapper){
if(trg.isSelected){
//propertySelectedOnLeasingActTab.add(prop.PropertyList.Id);
targetIdsSelectedFromLeasingActTab += '\'' + trg.targetList.Id + '\',';
}
}
 if(targetIdsSelectedFromLeasingActTab.length() > 1) {
targetIdsSelectedFromLeasingActTab = targetIdsSelectedFromLeasingActTab.substring(0, targetIdsSelectedFromLeasingActTab.length()-1);
 queryCondition = 'Where Target_List__c IN (' + targetIdsSelectedFromLeasingActTab + ') ';
}

//COLLECTING ALL THE TIER SELECTED BY THE USER TO FILTER THE SERACH
String tierSelectedFromLeasingActTab = '';
for(tierWrapperClass ti: tierWrapper){
if(ti.isTierChecked){
//Account__r.Tier__c
tierSelectedFromLeasingActTab += '\'' + ti.tierList + '\',';
}
}
if(tierSelectedFromLeasingActTab.length() > 1) {
tierSelectedFromLeasingActTab = tierSelectedFromLeasingActTab.substring(0, tierSelectedFromLeasingActTab.length()-1);
 if(queryCondition.length() == 0) {
queryCondition = 'Where Tier__c IN (' + tierSelectedFromLeasingActTab + ') ';
} else {
queryCondition += 'and Tier__c IN (' + tierSelectedFromLeasingActTab + ') ';
}
}
//System.debug('queryCondition 2 :'+queryCondition);

//PEROID VALUE SELECTED BY USER
Integer periodSelectedFromLeasingActTab = 0;
if(selectedPeriod != null && selectedPeriod.length() > 0 && selectedPeriod != 'All') {
 Date filterDate;
if('7'.equals(selectedPeriod)) {
filterDate = Date.today().addDays(-7);
} else if('28'.equals(selectedPeriod)) {
filterDate = Date.today().addDays(-28);
} else if('3M'.equals(selectedPeriod)) {
filterDate = Date.today().addMonths(-3);
} else if('6M'.equals(selectedPeriod)) {
filterDate = Date.today().addMonths(-6);
} else if('1Y'.equals(selectedPeriod)) {
filterDate = Date.today().addYears(-1);
}
//System.debug('filterDate: '+filterDate);

String dateVal = String.valueOf(filterDate) + 'T00:00:00.000Z';
 if(queryCondition.length() == 0) {
queryCondition = 'Where CreatedDate >= ' + dateVal + ' ';
} else {
queryCondition += 'and CreatedDate >= ' + dateVal + ' ';
}
}

//COLLECTING THE STATUS OPTIONS SELECTED BY USER TO FILTER THE SEARCH
String statusSelectedFromLeasingActTab = '';
for(statusWrapperClass sts: statusWrapper){
if(sts.isChecked){
statusSelectedFromLeasingActTab += '\'' + sts.statusList + '\',';
}
}
if(statusSelectedFromLeasingActTab.length() > 1) {
statusSelectedFromLeasingActTab = statusSelectedFromLeasingActTab.substring(0, statusSelectedFromLeasingActTab.length()-1);
 if(queryCondition.length() == 0) {
queryCondition = 'Where Status__c IN (' + statusSelectedFromLeasingActTab + ') ';
} else {
queryCondition += 'and Status__c IN (' + statusSelectedFromLeasingActTab + ') ';
}
}

 String retailSelectedFromLeasingActTab = '';
for(RetailUseWrapperClass rel: retailUseListLeasing){

if(rel.isSelected){

retailSelectedFromLeasingActTab += '\'' + rel.retailUse + '\',';

}
}
if(retailSelectedFromLeasingActTab.length() > 1) {
retailSelectedFromLeasingActTab = retailSelectedFromLeasingActTab.substring(0, retailSelectedFromLeasingActTab.length()-1);
System.debug('-----------------statusSelectedFromLeasingActTab-------------------: '+statusSelectedFromLeasingActTab);
if(queryCondition.length() == 0) {
queryCondition = 'Where Account__r.facility_category__c IN (' + retailSelectedFromLeasingActTab + ') ';
} else {
queryCondition += 'and Account__r.facility_category__c IN (' + retailSelectedFromLeasingActTab + ') ';
}
}


/*if(queryCondition.length() == 0) {
queryCondition = 'Where Account__c NOT IN (' + ids + ') ';
} else {
queryCondition += 'and Account__c NOT IN (' + ids + ') ';
} */

//COLLECTING THE ACTIVITY OPTIONS SELECTED BY USER TO FILTER THE SEARCH
Set<String> actAccounts = new Set<String>();
Set<String> actTargets = new Set<String>();
String activitySelectedFromLeasingActTab = '';
for(activityWrapperClass ats: activityWrapper){
if(ats.isChecked){
activitySelectedFromLeasingActTab += '\'' + ats.accStatus + '\',';
}
}
system.debug('------------------------activityWrapper------------------ : '+activityWrapper.size());
system.debug('---------------activitySelectedFromLeasingActTab------------------ : '+activitySelectedFromLeasingActTab);
String[] actArr;
if(activitySelectedFromLeasingActTab.length() > 0) {
actArr = activitySelectedFromLeasingActTab.split(',');
}
if(actArr != null && !(actArr.size() > 2)) {
activitySelectedFromLeasingActTab = activitySelectedFromLeasingActTab.substring(0, activitySelectedFromLeasingActTab.length()-1);
//System.debug('statusSelectedFromLeasingActTab: '+statusSelectedFromLeasingActTab);

List<Activity_History__c> ahlst = Database.query('Select ActivityType__c, Account__r.Name, Account__r.Id, Account__c,Target_List__c From Activity_History__c where ActivityType__c IN (' + activitySelectedFromLeasingActTab + ')');
for(Activity_History__c ah : ahlst) {

actAccounts.add(ah.Account__c);
actTargets.add(ah.Target_List__c);
}
/*if(queryCondition.length() == 0) {
queryCondition = 'Where Activity_History__r.ActivityType__c IN (' + activitySelectedFromLeasingActTab + ') ';
} else {
queryCondition += 'and Activity_History__r.ActivityType__c IN (' + activitySelectedFromLeasingActTab + ') ';
}*/

String ids1 = '';
for(String id : actAccounts) {
if(id != null) {
ids1 += '\''+id+'\''+',';
}
}

if(ids1.length() > 0) {
ids1 = ids1.substring(0,ids1.length()-1);
} else {
ids1 += '\''+''+'\'';
}

String ids2 = '';
for(String id : actTargets) {
if(id != null) {
ids2 += '\''+id+'\''+',';
}
}

if(ids2.length() > 0) {
ids2 = ids2.substring(0,ids2.length()-1);
} else {
ids2 += '\''+''+'\'';
}

if(queryCondition.length() == 0) {
queryCondition = 'Where Account__c IN (' + ids1 + ') ';
} else {
queryCondition += 'and Account__c IN (' + ids1 + ') ';
}

if(queryCondition.length() == 0) {
queryCondition = 'Where Target_List__c IN (' + ids2 + ') ';
} else {
queryCondition += 'and Target_List__c IN (' + ids2 + ') ';
}
}
if(queryCondition.length() == 0) {
queryCondition = 'Where Target_List__r.Property__r.Name != null ';
} else {
queryCondition += 'and Target_List__r.Property__r.Name != null ';
}
System.debug('--------------queryCondition------------------------:'+queryCondition);
//if(''.equals(queryCondition)) return;
leasingQuery = 'Select SFT__c, Tier__c, Contact_Name__c, Target_List__r.Property__c, Target_List__r.Property__r.Name, Target_List__r.Name, Target_List__c, Status__c, Rental_Space__c, LastModifiedDate, CreatedDate, Account__r.facility_category__c, Account__r.Name, Account__c, Account__r.facility_max_sq_ft__c,Account__r.facility_min_sq_ft__c From Account_Status__c ' + queryCondition;
String accStatusQuery = 'Select SFT__c, Tier__c, Contact_Name__c, Target_List__r.Property__c, Target_List__r.Property__r.Name, Target_List__r.Name, Target_List__c, Status__c, Rental_Space__c, LastModifiedDate, CreatedDate, Account__r.facility_category__c, Account__r.Name, Account__c,Account__r.facility_max_sq_ft__c,Account__r.facility_min_sq_ft__c From Account_Status__c ' + queryCondition;
List<List<Account_Status__c>> lstAccStatusList = new List<List<Account_Status__c>>();
integer count = 0;
List<Account_Status__c> lstStatus = new List<Account_Status__c>();
for(Account_Status__c aStatus: Database.query(accStatusQuery)) {
if(count < 1000) {
lstStatus.add(aStatus);
count++;

} else {
count = 0;

system.debug('----------1.lstStatus.size()------------'+lstStatus.size());
lstAccStatusList.add(lstStatus);
lstStatus = new List<Account_Status__c>();


}

}
system.debug('----------2.lstStatus.size()------------'+lstStatus.size());
if(lstStatus.size() < 1000) {
lstAccStatusList.add(lstStatus);
}
system.debug('----------3.lstStatus.size()------------'+lstStatus.size());
leasingAccountStatusList = Database.query(accStatusQuery);

if(leasingAccountStatusList != null && leasingAccountStatusList.size() > 0) {
leasingAccountStatusLisSize=leasingAccountStatusList.size();

System.debug('------------------leasingPrint-------------------- :'+leasingPrint.size());
//this.leasingPrint = prepareLeasingWrapperRecord(leasingAccountStatusList, 0, leasingAccountStatusLisSize);
lstleasingpdfList = new List<List<LeasingWrapperClass>>();
system.debug('----------lstAccStatusList.size()---------'+lstAccStatusList.size());
for(List<Account_Status__c> leasingAccountStatusList1 : lstAccStatusList) {
system.debug('----------leasingAccountStatusList1.size()---------'+leasingAccountStatusList1.size());
leasingpdf = prepareLeasingWrapperRecord(leasingAccountStatusList1, 0, 1000);
system.debug('----------leasingpdf.size()---------'+leasingpdf.size());
lstleasingpdfList.add(leasingpdf);
}
allLeasing.add(leasingpdf);
this.leasing = prepareLeasingWrapperRecord(leasingAccountStatusList, 0, pageSize);
this.leasingPrint = this.leasing;
this.allLeasing.add(this.leasing);
showLeasingPageLabel = true;
} else {
showLeasingBackPageLink = false;
showLeasingForwardPageLink = false;
showLeasingPageLabel = false;
}

}