3

I have visualforce page where i'm trying to get some data as part of page load, and some more data through remote function and modifying some of page input elements due to view state limitations. I'm seeing a weird behavior when I modify visualforce page through remote function data and post it, nothing is happening? I'm not even able to see my method getting called, wondering its due to security.

Page modification scenario, Stateful controller page load -> stateless call -> stateful post

Thanks

2
  • Please add some more details about your implementation, preferably including some trimmed-down snippets of your code Jun 16 '15 at 15:43
  • I have multi-page wizard controller where user go through lot of input selections for bulk update which is hitting view state limit, i'm trying to de-couple data loading part as async through visualforce remoting. 1. Page loads with existing input elements (if its edit), 2.build a selection/multi-select list for each wizard step (view state killer). 3. Post form page after each step in wizard controller. I'm seeing my controller getting refreshed instead of calling my controller method, i'm using commandlink action post. I want to know my assumption about the behavior is valid or not ?
    – realnumber
    Jun 16 '15 at 16:18
4

There's three possible approaches here, since view state is the problem.

Reduce View State by Transient

Make the select-options transient, so they don't take up view state size, and are rendered purely in Visualforce. You don't even need your inputs to be part of view state as long as they're part of the form. It's trivial to reduce view state size with the judicial use of the transient keyword. You'll want to experiment, because it does take some getting used to (e.g. you have to remember to have everything bound to an input element or re-rendered each time the page loads).

Make Client-Side UI

Render the entire UI in Angular, jQuery, or even vanilla JS. The client interacts with Visualforce only through RemoteAction functions. This is incredibly fast (usually up to 10x faster), at the cost of some complexity.

Hybrid Solution

Sometimes, you can get away with making a hybrid solution, which is easily as complicated as either prior solution, but gives you more control over the size of the view state. For example, you might have the core inputs be bound to hidden elements, and then linked through two-way data binding in AngularJS such that your apex:commandLink will only affect part of the page, and AngularJS will take care of rendering UI elements that are bound by templates. I've only attempted this a few times, and the payout was always worth it, but the complexity leaves something to be desired.

7
  • i will confirm the solution in few days after trying it, i was thinking along the hybrid solution too, since its an existing project, entire client side rework may be lot.
    – realnumber
    Jun 16 '15 at 17:21
  • just a question on the behavior, since i made stateless request and post a stateful form vf will not remember anything right?
    – realnumber
    Jun 16 '15 at 17:22
  • It's technically complicated. Personally, I'd strongly advise trying marking everything transient (I mean everything), then start making things non-transient until things stop breaking, then migrate the rest to hidden input elements or dynamic getters until your view state is non-existent. It's easier than trying to hybrid something that didn't start out that way. In fact, I think I'm going to write a transient page demo for people to learn from...
    – sfdcfox
    Jun 16 '15 at 17:25
  • @realnumber As a shorter answer, though, yes, Visualforce view state won't remember anything that happens from stateless calls, so you need a way to bridge the two together. That's why it's complicated.
    – sfdcfox
    Jun 16 '15 at 17:29
  • transient part already exist, the current optimization is beyond that to provide bulk record edit capacity for maximum possible records/relationships.
    – realnumber
    Jun 16 '15 at 17:37

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.