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
VPdVPd 

Render visualforce as PDF from Apex. View State Limit issue.

Hi All,

I have a visualforce page to render as PDF. This page has few images with total size as 5MB but it throws view state limit exception. The salesforce documention says "The maximum total size of all imagesincluded in a generated PDF is 30 MB". I don't have any controller variable(dynamic values) to show on the page. it all has static text, CSS and images.

Not sure why this view state limit hits given that the salesforce allows total image size as 30MB and imanges to show in my case is just 5MB. Any help or pointer on this would be greatly appreciated.

Thanks,
Suraj TripathiSuraj Tripathi
Hi Vpd,
Salesforce allows Visualforce pages to have a maximum view state size of 135KB.
The View State tab shows you which elements on your page are taking up that space.
A smaller view state size generally means quicker load times.
In order to avoid this error, minimize your pages' view state. You can optimize your Apex controller code and remove any superfluous Visualforce components used.
For example:
If you notice that a large percentage of your view state comes from objects used in controllers or controller extensions, consider refining your SOQL calls to return only data that's relevant to the Visualforce page.
If your view state is affected by a large component tree, try reducing the number of components your page depends on.
For more information regarding the View State read page 21 of the developer guide.Salesforce allows Visualforce pages to have a maximum view state size of 135KB.
The View State tab shows you which elements on your page are taking up that space.
A smaller view state size generally means quicker load times.
In order to avoid this error, minimize your pages' view state. You can optimize your Apex controller code and remove any superfluous Visualforce components used.
For example:
If you notice that a large percentage of your view state comes from objects used in controllers or controller extensions, consider refining your SOQL calls to return only data that's relevant to the Visualforce page.
If your view state is affected by a large component tree, try reducing the number of components your page depends on.
For more information regarding the View State read page 21 of the developer guide.

Reference : https://help.salesforce.com/articleView?id=000002955&type=1

Please let me know if it helps.

Thanks.
VPdVPd
Thanks Suraj for the insights. As i mentioned, i am not using any controller on the visualforce page. It  has only HTML Tags, CSS and image files. Can you please give more details on "large component tree" associated to  page? and how we can reduce the number of components without loosing information being rendered on the VF page?
Nikhil Verma 6Nikhil Verma 6
Can you check your view state size by enabling the developer mode and View State on the page. That will give you idea as to which components is consuming large space. Post that only you can take any actions.

Thanks.