The only reason Salesforce is trying to serialize the List<Messaging.SingleEmailMessage>
property is because you are adding it to the view stateView State
. You don't need to, however, as you do not reference it in your markup. Simply remove the messageList
property and scope it locally. If you really want to keep it as a property, mark it as transient
.
##Repro
The MVR is simple here:
Page
<apex:page controller="Demo">
<apex:form />
</apex:page>
Controller
public with sharing class Demo
{
public List<Messaging.SingleEmailMessage> messages { get; private set; }
public Demo()
{
messages = new List<Messaging.SingleEmailMessage>
{
new Messaging.SingleEmailMessage()
};
}
}
##Fix
Marking messages
as transient
resolves the error, as does removing it as a property and declaringscoping it only inlocally to the constructormethod where it is used.
Transient
public with sharing class Demo
{
public transient List<Messaging.SingleEmailMessage> messages { get; private set; }
public Demo()
{
messages = new List<Messaging.SingleEmailMessage>
{
new Messaging.SingleEmailMessage()
};
}
}
Locally scoped
public with sharing class Demo
{
public Demo()
{
List<Messaging.SingleEmailMessage> messages = new List<Messaging.SingleEmailMessage>
{
new Messaging.SingleEmailMessage()
};
}
}