0

I am getting the view state limit exceeded error. I have been reading about the transient keyword:

Declaring variables as transient reduces view state size. A common use case for the transient keyword is a field on a Visualforce page that is needed only for the duration of a page request, but should not be part of the page's view state and would use too many system resources to be recomputed many times during a request.

... My understanding is that, in a controller, in order to reduce the view state size, mark variables as transient that are needed in the controller logic but not needed to display the visual force page. Is that correct ?

public Practice__c practiceRecord {get; set;} 
    public User currentUser {get; set;} 
    public User practiceOwner;
    public Id practiceId;
    public List<HouseholdWrapper> activeHH {get; set;}
    public List<HouseholdWrapper> marketingHH {get; set;}
    public List<HouseholdWrapper> unassignedHH {get; set;}  
    public List<HouseholdWrapper> pageInUnassignedHouseHolds;
    public List<HouseholdWrapper> filteredUnassignedList{get; set;}
    public List<HouseholdWrapper> pageInActiveHouseHolds;
    public List<HouseholdWrapper> pageInMarketingHouseHolds;    
    public Practice_Assignment_Change__c pacRecord {get; set;}
    public List<Household__c> selectedUnassignedHouseholds{get; set;}
    public List<Household__c> selectedActiveHouseholds{get; set;}
    public List<Household__c> selectedMarketingHouseholds{get; set;}  
    public List<Household__c> householdCriteriaMet_False{get; set;} 
    public List<Household__c> updateHHList;     
    public List<Id> metCriteriaHH_Id;
    public List<Id> notMetCriteriaHH_Id;    
    public List<Household_Practice_Assignment_Change__c> hhPracticeAsignmentChangeRecords;
    public List<Household_Practice_Assignment_Change__c> hhNotMetCriteria {get;set;}
    public List<Household_Practice_Assignment_Change__c> tempListHPAssignChange_True = new List<Household_Practice_Assignment_Change__c>();
    public List<Household_Practice_Assignment_Change__c> tempListHPAssignChange_False = new List<Household_Practice_Assignment_Change__c>();
    public List<Household_Practice_Assignment_Change__c> list_HPAssignChange; 
    public Boolean displayPopupForUnassigned {get; set;}
    public Boolean displayPopupForActive {get; set;}
    public Boolean displayPopupForMarketing {get; set;}  
    public Boolean displayAlert {get;set;}
    public String buttonId {get; set;}    
    public String requested_status {get;set;}
    public List<String> userbranchList = new List<String>();
    public Boolean selectAll {get;set;}
    public HouseholdWrapper temp;

    /*-------Search functionality on unassigned HH-------*/
    public List<SelectOption> eligibilityList {get;set;}
    public List<SelectOption> managedList {get;set;}    
    public String selectedEligibility {get;set;}
    public String selectedManaged {get;set;}
    public Boolean managedFlag {get;set;}
    public String assetEligibleMin {get;set;} // CRMT-62953 From decimal to string 
    public String assetEligiblemax {get;set;}
    public Integer assetMaxEligibleBalance;
    public Integer notInteger = 0;
    public Integer totalSearchResult {get;set;}
    public String onLoad;
    public String state{get;set;}// CRMT-68325, CRMT-68322 

    /*----------Pagination-------*/
    private Integer counter_unassigned=0;  //keeps track of the unassigned offset
    private Integer counter_active = 0;  //keeps track of the active offset
    @TestVisible 
    private Integer counter_marketing = 0; //keeps track of the Marketing offset
    private Integer list_size = Integer.valueOf([SELECT List_Size_On_Page__c 
                                                 FROM Practice_Constants__mdt 
                                                 WHERE MasterLabel ='Default'].List_Size_On_Page__c); //Fixing the number of rows on a page
    public Integer total_Unassignedsize; //stores the total size of the unassigned list
    public Integer total_Activesize;//stores the total size of the active list
    public Integer total_Marketingsize;//stores the total size of the Marketing list 

    /*-----------Custom Labels---------*/
    public String clNoRecordsFound {get;set;}
    public String clHHMetCriteria {get;set;}
    public String clContinue {get;set;}
    public String fieldNames = Practice_Constants.PA_FieldNames;
    public String selectedEligibiliCondition; 
    public String userBranchCondition;  
    public Map<Id,List<Household__c>> pendingRequests{get;set;}
    public Id defaultUserId;            
    public String isAlpha {get;set;} //Error message if min and max value is alphabatic 

    //27698--Calculate PAC Fields
    public Decimal activeProjectedRevenue = 0;
    public Decimal marketingCount = 0;

    //CRMT-27684
    public Map<String,Decimal> calculatePotentialServicePay = new Map<String,Decimal>();
    public List<Calculate_PA_Fields__mdt> calculatePAFields = [SELECT Job_Code__c,Percentage__c 
                                                               FROM Calculate_PA_Fields__mdt];

    //48365    
    public Boolean isCurrentUserPAT;
    public Boolean isCurrentUserBM{get; set;}
    public Boolean isCurrentUserFC {get; set;}
    public Boolean isPATOrBMOrAdmin {get; set;}    
    public Household__c transferPractice {get; set;}  //Considering Household as HH is lookup to the Practice, considering HH instance can choose Practice.
    public String transfer_ErrorMessage {get; set;} 
    public List<Household__c> transferInBranchHH;            
    public List<Household__c> transferOutBranchHH {get;set;} 
    public List<Household__c> transferSelectedHH {get; set;} 

    //CRMT-68014    
    public String practiceDescription {get; set;} 

I have this huge list of variables should I transiate the ones that are needed only within the controller ?

Edit, to clarify my thinking:

I found this field

public List<Calculate_PA_Fields__mdt> calculatePAFields = [SELECT Job_Code__c,Percentage__c 
                                                               FROM Calculate_PA_Fields__mdt];

this field is only used to fill up another map, it is public however so I don't want to move it because I think it could be used somewhere else, is this the sort of variable that could easily be transient ?

3

If the variable is needed only one method, put the variable in the method instead of the global storage space. Anything that needs to be tracked between requests needs to be not-transient or it won't be stored. Anything bound to a form input element can be marked as transient. These are the three basic rules you should follow. It's not clear which variables are used for which, but you should be able to figure it out based on what I stated above.

|improve this answer|||||
  • to clarify, you can mark a form input element because every request will submit that data right and the controller doens't need to save it – SallyRothroat Jul 26 '18 at 19:07
  • @madmax Yes, if it's in the form, you don't need to have it be stored in the view state. – sfdcfox Jul 26 '18 at 19:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.