1

I have a custom page to preview and render Email templates, now i came across that some (not many) templates will exceed the view state of the page ( max 137kb) As I need the function to replace text within the template the displayed variable (transient) needs to be at some point be reassigned with a new value, but as soon i do that in the code (touching the value of that var again by assigning a new string the page drops out with the view state exceeded error (already on loading the page after selecting the template) if I don't "touch" the variable all is fine here is how i show the preview.

<apex:pageBlockSection title="Preview" columns="1"> 
            <apex:outputText value="{!theTempl}" escape="false" />
</apex:pageBlockSection>  

some other templates on the other hand work fine but one of them throws an error STRING_TOO_LONG, HTML Body: data value too large: As soon it goes to be assembled in a complete email But I could not find any limits for the EmailTemplate htmlValue

1) Does anyone got an idea how to avoid this view state thing, as this is only on some templates 2) How can I avoid this String too Long error, when all other actions ( string replace) went fine and only next stop is to send out the email

Thanks

1 Answer 1

0

I would refer you to the following docs/posts related to view state to help you troubleshoot the problems you're having with your templates. In some case, its a matter of needing to define your variables as transient to reduce the view state. It can also be one of needing to reduce the number of forms on the page, accessing too many objects at once, or simply needing to optimize your queries so you return only the info that's needed. Here's a list of docs and posts I think you'll find the most helpful to you:

2
  • Thanks for your comment, I tried this with transient as described and the only thing I load into the Controller for the Visualforcepage is vie apex: page the custom object controller and via query the bespoke ID and html value of the email template. I have read the article about view state, but even if i rip off anything else but sticking to the code i posted aboce , this already exceeds the view state ? on load as soon within the controller i exchange the string value, if i leave it alone it shows fine but as soon another process touches the transient variable its over!?
    – Moggy
    Commented Nov 24, 2014 at 8:25
  • Using the transient keyword was only one example of possible things that can be done where appropriate. Optimizing queries and clearing anything from memory no longer needed from your controller are examples of two other ones. Read the other docs for more specific examples, esp the 3rd & 4th ones which are posts from SF Dev Forum with comments from Gupta, Anora, TehNrd and other well known MVPs. Be sure to read the entire posts, not just the 'best answer' as code & good discussion follows.
    – crmprogdev
    Commented Nov 24, 2014 at 10:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .