Has anyone have the idea of passing the values as hidden in url

for example I need to pass the values of First Name,Last name,email,address & so on


If I pass them like that I'm getting a very large URl.Any remedy for this

  • Can you give a bit more background please. Where is the information coming from? Where is the URL generate produce from? Nov 12 '12 at 13:43
  • what andrew said, what is the purpose of the page? what are you going to do with the data? what must be done after the data was passed?
    – pjcarly
    Nov 12 '12 at 13:45
  • I'll be getting values of fn,ln etc from VF Page(say Page1) and displaying it in the page2 as {!fn} //in page fn = apexpages.currentpage().getparameters().get('fn'); //in constructor likewise need to display all the values in page2
    – Eagerin Sf
    Nov 12 '12 at 14:08

Ok two thoughts,

  1. Use HTTP POST rather than HTTP GET to pass the information. This is typically done as part of the form where the user originally entered the information.
  2. Pass an Id to a record that contains the information, the code behind the page rendering reads the record and retrieves the field values.

You appear to be using route 1 for page 1. In Visualforce to display another page with this information on simply return Page.page2 from your controller method responding to the input when page 1 is displayed. Visualforce reuses the viewstate if both pages have the same Apex controller defined.

In essence it transfers the viewstate from one page to another automatically this way, so no need to pass at all. The same bindings you used to capture the information on page1 can be used to display the information in page2.

Here is an example...

public with sharing class PagesController 
    public Account account {get;set;}
    public Contact contact {get;set;}

    public PagesController()
        account = new Account();
        contact = new Contact();            

    public PageReference page2()
        return Page.page2;

Page 1 looks like this...

enter image description here

<apex:page controller="PagesController">
    <apex:form >
        <apex:pageBlock title="Page 1" mode="edit">
            <apex:pageBlockButtons >
                <apex:commandButton value="Page 2" action="{!page2}"/>
            <apex:pageBlockSection title="Section" columns="2">
                <apex:inputField value="{!Account.Name}"/>
                <apex:inputField value="{!Contact.FirstName}"/>

Page 2 looks like this...

enter image description here

<apex:page controller="PagesController">
    <apex:pageBlock title="Page 2">
        <apex:pageBlockSection title="Section" columns="2">
            <apex:outputField value="{!Account.Name}"/>
            <apex:outputField value="{!Contact.FirstName}"/>

Hope this helps and enjoy!

P.S. Here is an example showing how to create a more complex wizard type ui.

  • 1.Information coming from a VFpage1 into page2 2.I don't have any custom object for this.Saved values are going into different objects(say account,contact,customobject1,customobject2) so can't get a particular id
    – Eagerin Sf
    Nov 12 '12 at 14:15
  • Yes, in this case your using option 1, standard form submit and displaying a new page. Let me put a small sample in the answer. Nov 12 '12 at 14:18
  • yes...It worked out like a charm.now can I pass this values as a site link(example-developer-edition.ap1.force.com/site) in email...
    – Eagerin Sf
    Nov 12 '12 at 15:05
  • Your most welcome! :) Nov 12 '12 at 16:50
  • I want this same feature.but i want that user register in visualforce page and on submitting the page a link of site page is emailed to him appended with the record id.i want to hide that id.how can i do this.for eg i am sending link:www.mysite.salesforce.com/apex/rec/id=?1456987456665547.i want this id field to be hidden.
    – Pankaj
    Mar 21 '13 at 12:33

Though this post is old, you can set your data in a Cookie.

public class UriData {
    public String email {get;set;}
    public String address {get;set;}
    public Date importantDate {get;set;}

    public UriData(String email, String address, Date importantDate){
        this.email = email;
        this.address = address;
        this.importantDate = importantDate;

    public String toJson(){
        return JSON.serialize(this);

public static final UriDataCookieName = 'uriDataCookieName';

public static void setUriDataCookie(UriData uriData){
    String uriDataJson = uriData == null ? '' : uriData.toJson();
    System.Cookie cookie = new System.Cookie(
        UriDataCookieName, // Name
        uriDataJson,       // value
        null,              // path
        -1,                // maxAge - -1 for Session Cookie
        true               // isSecure
    ApexPages.currentPage().setCookies(new System.Cookie[]{cookie});

public static UriData getUriData(){
    // Called in Next Page's Controller.
    System.Cookie cookie = ApexPages.currentPage().getCookies().get(UriDataCookieName);
    String uriDataJson = cookie == null ? '' : cookie.getValue();
    UriData uriData;
    try {
        uriData = (UriData) JSON.deserialize(uriDataJson, UriData.class);
    } catch(Exception whoops){
        uriData = new UriData(null, null, null);
    return uriData;

Assuming Page 2 is returned via invocation of an action method (following a button click or such on Page 1), you can return a PageReference with the http parameters set.

PageReference page2 = new       PageReference('/apex/Page2');
page2.getParameters.put('paramName', 'paramValue');

This appends to the URL and is alright so long as you don't exceed the maximum permissible length for a URL, which is approximately 2000 chars.

You could also overload (abuse) http headers and use custom headers to pass parameters.

page2.getHeaders().put('Date', '9/9/99');

Sharing a controller like Andy has pointed out is probably the more elegant solution.

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.