Visualforce – Best way to pass 10 to 15 parameters from one page to another

What is the best practice to pass more than 10 parameters from one page to other page. Is there any way other than passing the values in the url or using the same controller.

PS : Can this be done using static variables?


There are a few other ways you could accomplish this. The following options are provided in no specific order, and should not be interpreted as an order of preference.

First, if the value is less than about 4kb worth of data, you could set cookies, perhaps setting one cookie per value or even JSON-encoding the data (serialize) from the source and then JSON-decoding the data (deserialize) at the destination.

Second, you could always store the data somewhere safe, like a personal Document, which you could then retrieve by Id; this way, you’re only sending one parameter across the wire.

Third, you could use the Platform Cache, if you have it available to you. It does come at some cost (as I understand it), but it’s incredibly handy for storing data temporarily.

Fourth, you could use a Custom Setting of the Hierarchy type. Perhaps a bit overkill, but it would allow you to structure the data and set/get it as needed. It’s a bit more permanent than the cache (which could disappear at any time), but it’s a free feature, and you can just delete the values when you’re done.

Fifth, you could use localStorage along with some apex:actionFunction JavaScript to set the values on page unload (on the sending side), and loading it back at the destination. This would be a more AJAX-y approach that would provide a more responsive UI. The limit here is about 2,500,000 Unicode characters, which is more than almost any other option can provide, except for using Documents.

Explicitly referencing static variables, however… you can’t rely on this working even if you share a controller, because those variables are transient, and wouldn’t survive the trip across transactions.

Personally, I’d suggest using session cookies if the data should fit within the allocated space, as it’s free and is client specific. However, if you’re worried about users peeking at the data, you might want to encrypt the cookies beforehand when using cookies or a Document. Custom settings and the Platform Cache don’t need to be encrypted normally, as only administrators can see that data, though. Just remember that both of those features are server-side and have pretty severe limitations (1MB per license with a maximum of 10MB).

Source : Link , Question Author : shannu , Answer Author : sfdcfox

Leave a Comment