Find your content:

Search form

You are here

Need to Pass the values as hidden in Url in Salesforce

 
Share

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

\apex\page2?fn=test&ln=test&email=vemula.aruna@clickandpledge.biz&bill=adres,adres2,city,508209,840,Alabama,&tdate=12/11/12

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


Attribution to: Eagerin Sf

Possible Suggestion/Solution #1

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;
}

Attribution to: Scott Pelak

Possible Suggestion/Solution #2

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:pageBlockButtons>
            <apex:pageBlockSection title="Section" columns="2">
                <apex:inputField value="{!Account.Name}"/>
                <apex:inputField value="{!Contact.FirstName}"/>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>

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}"/>
        </apex:pageBlockSection>
    </apex:pageBlock>
</apex:page>

Hope this helps and enjoy!

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


Attribution to: Andrew Fawcett

Possible Suggestion/Solution #3

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.


Attribution to: techtrekker
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/4292

My Block Status

My Block Content