3

The 2 ways of passing parameters to another page that i know of are

  1. Use the pageReference class and use its getParameter method to assign parameters

    pageReference pr = Page.page1;
    pr.getParameters().put('param1',param);
    
  2. Build a url using string and pass it to pagereference class

    String url = '/apex/page1?param1=param 
    pr = new PageReference(url);pr.setRedirect(true); 
    

Are there anyother way we can pass params? What are differences in terms of best practice or performance or security

Or are they just the same?

  • If you hand-craft the URL it's your job to do the url encoding for one thing? – eyescream May 14 '13 at 12:12
7

They're the same, you will see any parameters added via addParameters in the URL as query parameters.

A more secure way to do it would be sharing a controller across Visualforce pages, in which case you wouldn't need to pass parameters between pages. However for this, I believe redirect needs to be false, or else it flushes the ViewState.

  • 2
    What you say at the end is correct. – pjcarly May 14 '13 at 11:47
  • 2
    Agree, I think the whole passing of view state topic needs more calling out in the docs. So many people resort to URL params because its not that well know. If the page standard controller and/or extensions are compatibile the view state will be shared, otherwise regardless of the redirect parameter, the state will not be shared. – Andrew Fawcett May 14 '13 at 11:59

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.