2

To avoid an object from getting too big I'm building seperate objects with their own Visualforce component pages. The main Visualforce page uses tabs where I am calling each componenet page.

By doing this will the viewstate on the main page be kept under the limit ? Or do called component Visualforce pages add to the main page view state ?

Also, how can I relate all of the Visualforce components to the main Visualforce page for reporting ?

Unfortunately I'm dealing with many fields and don't want to run into view state errors forcing me to write more HTML along with any transient property definitions in the controller (which is very light.)

4

The answer is anything on the VF page, counts towards view state.

And that you got all other details as provided by sfdcfox, you can actually do a very quick test to check how your view state is impacted with or without using <apex:component>.

You can do a very quick check using an example and see how the view state changes.

As an example, using the below component and vf page code, you can see the difference how the view state is impacted. This kind of will give you an idea that anything on the page is going to impact your view state.

Component

<apex:component >
    <h1>Congratulations</h1>
    This is your new Component: mynewcomponent
</apex:component>

VF Page without component

<apex:page controller="ContactEditController">
    <apex:form >
        This is my VF Page<br/>
    </apex:form>
</apex:page>

View State in this case is as: enter image description here

VF Page with component

<apex:page controller="ContactEditController">
    <apex:form >
        This is my VF Page<br/>
    </apex:form>
    <c:myVFComponent />
</apex:page>

View State in this case increases: enter image description here

1
  • Thanks. Interesting. I;m also using the <apex:include> tag . The view state seems to take a big hit with the component. What would be the advantage of using the Include .vs Component tags ?
    – rickmac
    May 17 '18 at 15:00
3

By doing this will the viewstate on the main page be kept under the limit ? Or do called component Visualforce pages add to the main page view state ?

Everything in the page increases the view state. Best case scenario, it will do absolutely nothing to improve this problem, and most likely it will exacerbate it.

Also, how can I relate all of the Visualforce components to the main Visualforce page for reporting ?

This happens automatically by the virtue of metadata relationships, but you can't really query on it.

Unfortunately I'm dealing with many fields and don't want to run into view state errors forcing me to write more HTML along with any transient property definitions in the controller (which is very light.)

Sorry, that's the nature of the beast. You need to figure out what you can make transient in order to minimize view state. This is a major limitation of Visualforce, and one of the main reasons why Lightning is so effective.

4
  • Thanks. We're still on the classic platform. Can you say more as to why lightning would be better ? Does it have a higher or no view state limitation ?
    – rickmac
    May 17 '18 at 14:58
  • @rickmac In Lightning Components, the view is maintained in memory and never sent to the server. The trade-off for this design is that you have to explicitly specify what you want to send to the server (e.g. if you need to a query, update a record, etc). View state is no longer relevant in Lightning because everything is rendered on the client (browser), instead of rendered on the server and sent in HTML format (Visualforce). This makes Lightning faster and more responsive.
    – sfdcfox
    May 17 '18 at 15:03
  • @rickmac You can also use Lightning in Visualforce (the page is just a container) and gain all the performance benefits of Lightning without switching to the Lightning Experience, and you'll also be designing in a forward-compatible way when you do decide to switch to the Lightning Experience.
    – sfdcfox
    May 17 '18 at 15:05
  • @rickmac Sorry, one more addendum; I said you can't query on the metadata relationships, and that's true for the moment, but there's a new dependency API that may become available at some point in the future (it's in a pilot right now).
    – sfdcfox
    May 17 '18 at 15:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.