+ Start a Discussion
JeffStevensJeffStevens 

Custom messages

I keep getting this error...

Content cannot be displayed: Not Serializable: ApexPages.Message

 

I have This in my controller extension...

public  ApexPages.Messagemsg{get;set;}

...

msg = new ApexPages.Message(ApexPages.Severity.WARNING, 'Must have a Re-Formatted file first...');
ApexPages.addMessage(msg);

 

And I have this in my markup...

<apex:Messages />

 

Do I have to create a custom exception message?  Or is there another way to display a custom error message?

 

Thanks


Best Answer chosen by Admin (Salesforce Developers) 
sfdcfoxsfdcfox

Don't use a member variable that will serialize a message. It won't work. Just change your code thusly:

 

ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.WARNING, 'Must have a Re-Formatted file first...'));

If you don't like constructing parameters directly, you can do this as well:

 

apexpages.message msg = new ApexPages.Message(ApexPages.Severity.WARNING, 'Must have a Re-Formatted file first...');
apexpages.addmessage(msg);

 

All Answers

sfdcfoxsfdcfox

Don't use a member variable that will serialize a message. It won't work. Just change your code thusly:

 

ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.WARNING, 'Must have a Re-Formatted file first...'));

If you don't like constructing parameters directly, you can do this as well:

 

apexpages.message msg = new ApexPages.Message(ApexPages.Severity.WARNING, 'Must have a Re-Formatted file first...');
apexpages.addmessage(msg);

 

This was selected as the best answer
JeffStevensJeffStevens

Wow - that was it!

 

I sure chased my tail around on that one for quite awhile.

 

Thanks so much!