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
josh bowesjosh bowes 

Form tag causes serialization error when extension controller contains describe call

Hello,
I've got some Visualforce pages that use controllers which contain describe calls to get picklist values. The picklist values are being used to populate Google visualizaition API data.

Any time I add an <apex:form> tag to the Visualforce, the page returns:
System.SerializationException: Not Serializable: Schema.DescribeFieldResult

Here are the controller and visualforce. The first VF example works fine, the second returns the error above - the only difference is the form tag.

Controller:

public class myextensioncontroller {

    private final myobject__c myobject;
    public myextensioncontroller(ApexPages.StandardController stdController) {
  this.myobject = (myobject__c)stdController.getRecord();  
    }
 
 Schema.DescribeFieldResult p = myobject__c.mypicklist__c.getDescribe();
 List<Schema.PicklistEntry> stgvals = p.getPicklistValues();


 public List<myobject__c> getmyobjectdata(){
  return [select id, name from myobject__c]; 
 }

}

 
Visualforce that works:
<apex:page standardcontroller="myobject__c" extensions="myextensioncontroller">
   
   <apex:pageblock >
        <apex:pageblocktable value="{!myobjectdata}" var="myobj">
            <apex:column value="{!myobj.name}"/>
        </apex:pageblocktable>
    </apex:pageblock>  
    
</apex:page>

 Visualforce that returns serialization error:
<apex:page standardcontroller="myobject__c" extensions="myextensioncontroller">
   
   <apex:form></apex:form>

   <apex:pageblock >
        <apex:pageblocktable value="{!myobjectdata}" var="myobj">
            <apex:column value="{!myobj.name}"/>
        </apex:pageblocktable>
    </apex:pageblock>  
    
</apex:page>

 
This is causing me a lot of headaches because I can't use commandlink or commandbutton - does anyone see what the problem is? Is this a bug or am I doing something wrong?

jwetzlerjwetzler
When you use a form all of the non-transient data in your controller has to be serializable in order for us to store your view state.  I don't think it's necessary for you to maintain this data in your view state.

You can either move your describe call out of a local variable and into the method that is going to be using it (I assume the end goal is to generate a list of SelectOptions containing the picklist values? if so you can move it into the getter that builds up the options) or you can use the transient keyword for p and stgvals.
josh bowesjosh bowes
Transient solved my problem, thanks very much for your quick reply!
MananShahMananShah

By defining DescribeSObjectResult variable in local method, it solved my problem of getting Serialization Exception error.

 

Thanks