You need to sign in to do that
Don't have an account?
SATHISH REDDY.
View State Error while working on 200+ records which are editable
Hi All,
Hope someone could help me resolve this issue. I have an Accounts List visualforce page with 3 tabs which shows 200+ records each which are editable from this vf page. However am hitting the view state error which am unable to get around with. Below is the VF page & Controller
Hope someone could help me resolve this issue. I have an Accounts List visualforce page with 3 tabs which shows 200+ records each which are editable from this vf page. However am hitting the view state error which am unable to get around with. Below is the VF page & Controller
public with sharing class AccListMassUpdateStatusTABController_AC { public List<cContact> contactsList { get; set; } public List<userWrapper> usersList { get; set; } public String passSelectedContactId { get; set; } public String passSelectedContact { get; set; } public String passSelectedContactTitle { get; set; } public List<Contact> contacts; public List<User> users; public Boolean view { get; set; } public Boolean edit { get; set; } public List<aAccount> lstaAccs { get; set; } public Id accId { get; set; } public Account agencyAcc; public Id selaccId { get; set; } public String passSelectedUserId { get; set; } public String passSelectedUser { get; set; } public emailWrapper emailWrap { get; set; } public String varTabId { get; set; } public AccListMassUpdateStatusTABController_AC() { varTabId = 'Directx'; view = true; edit = false; contactsList = new List<cContact >(); usersList = new List<userWrapper>(); lstaAccs = new List<aAccount>(); if(Apexpages.currentPage().getParameters().containsKey('Id')){ accId = Apexpages.currentPage().getParameters().get('Id'); } else{ fetchlstaAccs(); } } public void toggleSort() { // simply toggle the direction sortDir = sortDir.equals('asc') ? 'desc' : 'asc'; // run the query again fetchlstaAccs(); } public String sortDir { get { if(sortDir == null) { sortDir = 'desc'; } return sortDir; } set; } public String sortField { get { if(sortField == null) { sortField = 'CreatedDate'; } return sortField; } set; } /* public String tabName { get { if (tabName == null) {tabName = 'Primary'; } return tabName; } set; } */ public List<aAccount> fetchlstaAccs() { //get{ String SOQL = ''; // if (!lstaAccs.isEmpty()) lstaAccs.clear(); Id ownerid = Userinfo.getUserId(); system.debug('lstaAccsBeforeQuery == ' + varTabId + ' lstaAccs == ' + lstaAccs); if(varTabId == 'Primary') { SOQL = 'SELECT Id,Name,Contacts__c,current_status__c,Background__c,Next_Steps__c, Activity_Type__c, Meeting_Type__c,'; SOQL += 'lastmodifieddate FROM Account WHERE OwnerId=:ownerid '; SOQL += ' order by ' + sortField + ' ' + sortDir + ' LIMIT 500'; }else if(varTabId == 'Secondary') { SOQL = 'SELECT Id,Name,Contacts__c,current_status__c,Background__c,Next_Steps__c, Activity_Type__c, Meeting_Type__c,'; SOQL += 'lastmodifieddate FROM Account WHERE Secondary_Account_Owner__c != \'\' and Secondary_Account_Owner__c=:ownerid '; SOQL += ' order by ' + sortField + ' ' + sortDir + ' LIMIT 500'; }else if(varTabId == 'Directx'){ SOQL = 'SELECT Id,Name,Contacts__c,current_status__c,Background__c,Next_Steps__c, Activity_Type__c, Meeting_Type__c,'; SOQL += 'lastmodifieddate FROM Account WHERE Direct_Beta_Client__c = true'; SOQL += ' order by ' + sortField + ' ' + sortDir + ' LIMIT 500'; } lstaAccs.clear(); for(Account a: database.query(SOQL)) { lstaAccs.add(new aAccount(a, a.Id, a.Name, a.current_status__c, a.Background__c, a.Next_Steps__c, a.Activity_Type__c, a.Meeting_Type__c, string.ValueOf(a.lastmodifieddate))); } } public pageReference setActiveDirectxTab() { varTabId = 'Directx'; if(!lstaAccs.isEmpty()) lstaAccs.clear(); system.debug('varTabIdActive == ' + varTabId); fetchlstaAccs(); return null; } public pageReference setActiveSecondaryTab() { varTabId = 'Secondary'; if(!lstaAccs.isEmpty()) lstaAccs.clear(); system.debug('varTabIdActive == ' + varTabId); fetchlstaAccs(); return null; } public pageReference setActiveTab() { varTabId = 'Primary'; if(!lstaAccs.isEmpty()) lstaAccs.clear(); system.debug('varTabIdActive == ' + varTabId); fetchlstaAccs(); return null; } public class aAccount { public Id AccId { get; set; } public Account Acc { get; set; } public String AccName { get; set; } public String currentstatus { get; set; } public String Background { get; set; } public String NextSteps { get; set; } public String ActivityType { get; set; } public String MeetingType { get; set; } public string LastModified { get; set; } public aAccount(Account acct, Id aAccountId, string aAccName, string acurrentstatus, string aBackground, string aNextSteps, string aActivityType, string aMeetingType, string LastModifiedDate) { system.debug('acct == ' + acct); system.debug('aContacts == ' + aContacts); this.AccName = aAccName; this.Acc = acct; this.AccId = aAccountId; this.currentstatus = acurrentstatus; this.Background = aBackground; this.NextSteps = aNextSteps; this.ActivityType = aActivityType; this.MeetingType = aMeetingType; this.LastModified = LastModifiedDate; } } public pagereference save() { view = true; edit = false; List<Account> lstAccsToUpdate = new List<Account>(); Map<Id, aAccount> mapOrgaAccs = new Map<Id, aAccount>(); List<aAccount> oldaAccs = new List<aAccount>(); String SOQL = ''; if(varTabId == 'Primary') { SOQL = 'SELECT Id,Name,Contacts__c,current_status__c,Background__c,Next_Steps__c, Activity_Type__c, Meeting_Type__c,'; SOQL += 'lastmodifieddate FROM Account WHERE OwnerId = \'' + UserInfo.getUserId() + '\''; SOQL += ' order by ' + sortField + ' ' + sortDir + ' LIMIT 500'; } else if(varTabId == 'Secondary') { SOQL = 'SELECT Id,Name,Contacts__c,current_status__c,Background__c,Next_Steps__c, Activity_Type__c, Meeting_Type__c,'; SOQL += 'lastmodifieddate FROM Account WHERE Secondary_Account_Owner__c != \'\' and Secondary_Account_Owner__c= \'' + UserInfo.getUserId() + '\''; SOQL += ' order by ' + sortField + ' ' + sortDir + ' LIMIT 500'; } else if(varTabId == 'Directx') { SOQL = 'SELECT Id,Name,Contacts__c,current_status__c,Background__c,Next_Steps__c, Activity_Type__c, Meeting_Type__c,'; SOQL += 'lastmodifieddate FROM Account WHERE Direct_Beta_Client__c = true'; SOQL += ' order by ' + sortField + ' ' + sortDir + ' LIMIT 500'; } List<Account> oldAccounts = database.query(SOQL); for(Account a: oldAccounts) { oldaAccs.add(new aAccount(a, a.Id, a.Name, a.current_status__c, a.Background__c, a.Next_Steps__c, a.Activity_Type__c, a.Meeting_Type__c, string.ValueOf(a.lastmodifieddate))); } try { for(aAccount a : lstaAccs){ mapOrgaAccs.put(a.acc.Id, new aAccount(a.acc, a.acc.Id, a.acc.Name, a.acc.current_status__c, a.acc.Background__c, a.acc.Next_Steps__c, a.acc.Activity_Type__c, a.acc.Meeting_Type__c, string.ValueOf(a.acc.lastmodifieddate))); } for(aAccount a: oldaAccs) { if (mapOrgaAccs.containsKey(a.acc.Id) && (mapOrgaAccs.get(a.Acc.Id).currentstatus != a.Acc.Current_Status__c || mapOrgaAccs.get(a.Acc.Id).Background != a.Acc.Background__c || mapOrgaAccs.get(a.Acc.Id).NextSteps != a.Acc.Next_Steps__c || mapOrgaAccs.get(a.Acc.Id).ActivityType != a.Acc.Activity_Type__c || mapOrgaAccs.get(a.Acc.Id).MeetingType != a.Acc.Meeting_Type__c )) { lstAccsToUpdate.add(mapOrgaAccs.get(a.Acc.Id).acc); } } if(!lstAccsToUpdate.isEmpty()) { System.debug('lstAccsToUpdate*** '+lstAccsToUpdate); update lstAccsToUpdate; fetchlstaAccs(); } } catch (DMlException e) { ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR, 'Error: Save Failed Due to :' + e); ApexPages.addMessage(myMsg); return null; } return null; } public pagereference cancel() { edit = false; view = true; return null; } public pagereference Edit() { edit = true; view = false; return null; } }
This is the page