Skip to main content
added 15 characters in body
Source Link
Adrian Larson
  • 151.3k
  • 38
  • 247
  • 431

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()
        };
    }
}

The only reason Salesforce is trying to serialize the List<Messaging.SingleEmailMessage> property is because you are adding it to the view 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 declaring it only in the constructor.

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()
        };
    }
}

The only reason Salesforce is trying to serialize the List<Messaging.SingleEmailMessage> property is because you are adding it to the View 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 scoping it locally to the method 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()
        };
    }
}
deleted 63 characters in body
Source Link
Adrian Larson
  • 151.3k
  • 38
  • 247
  • 431

The only reason Salesforce is trying to serialize the List<Messaging.SingleEmailMessage> property is because you are adding it to the view 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="DemoExtension">controller="Demo">
    <apex:form />
</apex:page>

Controller

public with sharing class DemoExtensionDemo
{
    public List<Messaging.SingleEmailMessage> messages { get; private set; }
    public DemoExtensionDemo()
    {
        messages = new List<Messaging.SingleEmailMessage>
        {
            new Messaging.SingleEmailMessage()
        };
    }
}

##Fix

Marking messages as transient resolves the error, as does removing it as a property and declaring it only in the constructor.

Transient

public with sharing class DemoExtensionDemo
{
    public transient List<Messaging.SingleEmailMessage> messages { get; private set; }
    public DemoExtensionDemo()
    {
        messages = new List<Messaging.SingleEmailMessage>
        {
            new Messaging.SingleEmailMessage()
        };
    }
}

Locally scoped

public with sharing class DemoExtensionDemo
{
    public DemoExtensionDemo()
    {
        List<Messaging.SingleEmailMessage> messages = new List<Messaging.SingleEmailMessage>
        {
            new Messaging.SingleEmailMessage()
        };
    }
}

The only reason Salesforce is trying to serialize the List<Messaging.SingleEmailMessage> property is because you are adding it to the view 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="DemoExtension">
    <apex:form />
</apex:page>

Controller

public with sharing class DemoExtension
{
    public List<Messaging.SingleEmailMessage> messages { get; private set; }
    public DemoExtension()
    {
        messages = new List<Messaging.SingleEmailMessage>
        {
            new Messaging.SingleEmailMessage()
        };
    }
}

##Fix

Marking messages as transient resolves the error, as does removing it as a property and declaring it only in the constructor.

Transient

public with sharing class DemoExtension
{
    public transient List<Messaging.SingleEmailMessage> messages { get; private set; }
    public DemoExtension()
    {
        messages = new List<Messaging.SingleEmailMessage>
        {
            new Messaging.SingleEmailMessage()
        };
    }
}

Locally scoped

public with sharing class DemoExtension
{
    public DemoExtension()
    {
        List<Messaging.SingleEmailMessage> messages = new List<Messaging.SingleEmailMessage>
        {
            new Messaging.SingleEmailMessage()
        };
    }
}

The only reason Salesforce is trying to serialize the List<Messaging.SingleEmailMessage> property is because you are adding it to the view 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 declaring it only in the constructor.

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()
        };
    }
}
deleted 12 characters in body
Source Link
Adrian Larson
  • 151.3k
  • 38
  • 247
  • 431

The only reason Salesforce is trying to serialize the List<Messaging.SingleEmailMessage> property is because you are adding it to the view 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="DemoExtension">
    <apex:form />
</apex:page>

Controller

public with sharing class DemoExtension
{
    public List<Messaging.SingleEmailMessage> messages { get; private set; }
    public DemoExtension()
    {
        messages = new List<Messaging.SingleEmailMessage>
        {
                new Messaging.SingleEmailMessage()
        };
    }
}

##Fix

Marking messages as transient resolves the error, as does removing it as a property and declaring it only in the constructor.

Transient

public with sharing class DemoExtension
{
    public transient List<Messaging.SingleEmailMessage> messages { get; private set; }
    public DemoExtension()
    {
        messages = new List<Messaging.SingleEmailMessage>
        {
                new Messaging.SingleEmailMessage()
        };
    }
}

Locally scoped

public with sharing class DemoExtension
{
    public DemoExtension()
    {
        List<Messaging.SingleEmailMessage> messages = new List<Messaging.SingleEmailMessage>
        {
                new Messaging.SingleEmailMessage()
        };
    }
}

The only reason Salesforce is trying to serialize the List<Messaging.SingleEmailMessage> property is because you are adding it to the view 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="DemoExtension">
    <apex:form />
</apex:page>

Controller

public with sharing class DemoExtension
{
    public List<Messaging.SingleEmailMessage> messages { get; private set; }
    public DemoExtension()
    {
        messages = new List<Messaging.SingleEmailMessage>
        {
                new Messaging.SingleEmailMessage()
        };
    }
}

##Fix

Marking messages as transient resolves the error, as does removing it as a property and declaring it only in the constructor.

Transient

public with sharing class DemoExtension
{
    public transient List<Messaging.SingleEmailMessage> messages { get; private set; }
    public DemoExtension()
    {
        messages = new List<Messaging.SingleEmailMessage>
        {
                new Messaging.SingleEmailMessage()
        };
    }
}

Locally scoped

public with sharing class DemoExtension
{
    public DemoExtension()
    {
        List<Messaging.SingleEmailMessage> messages = new List<Messaging.SingleEmailMessage>
        {
                new Messaging.SingleEmailMessage()
        };
    }
}

The only reason Salesforce is trying to serialize the List<Messaging.SingleEmailMessage> property is because you are adding it to the view 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="DemoExtension">
    <apex:form />
</apex:page>

Controller

public with sharing class DemoExtension
{
    public List<Messaging.SingleEmailMessage> messages { get; private set; }
    public DemoExtension()
    {
        messages = new List<Messaging.SingleEmailMessage>
        {
            new Messaging.SingleEmailMessage()
        };
    }
}

##Fix

Marking messages as transient resolves the error, as does removing it as a property and declaring it only in the constructor.

Transient

public with sharing class DemoExtension
{
    public transient List<Messaging.SingleEmailMessage> messages { get; private set; }
    public DemoExtension()
    {
        messages = new List<Messaging.SingleEmailMessage>
        {
            new Messaging.SingleEmailMessage()
        };
    }
}

Locally scoped

public with sharing class DemoExtension
{
    public DemoExtension()
    {
        List<Messaging.SingleEmailMessage> messages = new List<Messaging.SingleEmailMessage>
        {
            new Messaging.SingleEmailMessage()
        };
    }
}
Source Link
Adrian Larson
  • 151.3k
  • 38
  • 247
  • 431
Loading