I'm trying to pass the value from a page variable to another page (both using different controller) without using parameters.

This is what am working on that.

I have user search page with input field.

It's a user search,If the user not found in the search, i provide the link below and says that click here to register. The input field search value which i have give should be populated in the Another page.

To achieve this how to pass the value, Please help me on this.

Page 1:

<apex:page controller="SearchPageController" sidebar="false" showHeader="false" docType="html-5.0" cache="false" id="pg">
    .slds-scope .slds-box {
    padding: 2rem;
    border-radius: 1.25rem;
    border: 4px solid #a4bfe4;
    width: 100%;
    padding-left: 55px;
    padding-right: 55px;
    margin: 0 auto;        
    background-color: #fdfdfd;
    border: 2px solid #a4bfe4;   
    border-radius: 1.25rem;
    padding-left: 5px;
    width: 25%;
    height : 30%;

<apex:form id="fm">


    function conRec () {
        //  alert('conRec');
        var pattern = /^\w+@[a-zA-Z_]+?\.[a-zA-Z]{2,3}$/;
        var SearchVal = document.getElementById('pg:fm:pb:SearchValue').value;

    <apex:slds />
    <apex:pageBlock id="pb" >

        <div class="slds-scope slds-box">
            <apex:outputPanel >                   
                <div id="formBlock">

                    <div id="showErrorMsgbuserName">
                        <div class="slds-form-element">
                            <div class="slds-align_absolute-center">
                                <!--- <apex:input value="{!searchBoxstring}"  id="SearchID" styleClass="searchBox"/>  --->

                                <apex:input value="{!searchBoxstring}" styleClass="searchBox" id="SearchValue" />
                                &nbsp;  &nbsp;  &nbsp; <apex:commandButton value="Search" onClick="conRec()" action="{!display}"   >

                                <div class="slds-hide slds-form-element__help" id="error-message-userName">This field is required</div>


                <apex:pageMessages id="Error" escape="false" />

                <apex:dataTable value="{!result}" var="con" border="1" cellpadding="5" cellspacing="4" bgcolor="lightblue">
                    <apex:column value="{!con.Name}" styleClass="controls">
                        <apex:facet name="header">Name</apex:facet>
                    <apex:column value="{!con.Email}" styleClass="controls">
                        <apex:facet name="header">Email</apex:facet>
                    <apex:column value="{!con.Phone}" styleClass="controls">
                        <apex:facet name="header">Phone</apex:facet>




public class SearchPageController {

public string searchboxstring{get; set;}
public String Email{get;set;}

public list<contact> result {get; set;}

public SearchPageController()
    result = new list<Contact>();

public pagereference display(){
    system.debug('searchboxstring1-->' + searchboxstring);
    Email = searchboxstring;        
    result=new List<Contact>();
    system.debug('searchboxstring-->' + searchboxstring);
    Email = searchboxstring;
    system.debug('Email-->' + Email);
    //result=[select ID, Name, Email, Phone  from Contact where FirstName like :searchboxstring or LastName  like :searchboxstring or Email like :searchboxstring or Phone like :searchboxstring];
    result=[select ID, Name, Email, Phone  from Contact where Name like :searchboxstring or Email like :searchboxstring or Phone like :searchboxstring];
    system.debug('result-->' + result.size());
    if (result.size() < 1) {            
        ApexPages.addmessage(new ApexPages.message(ApexPages.Severity.ERROR,'No data Found' + '<a href='+ System.URL.getSalesforceBaseUrl().toExternalForm()+ '/apex/Registration' + '>Click Here</a>' + 'to Register  Or '+ '<a href='+ System.URL.getSalesforceBaseUrl().toExternalForm()+ '/apex/Registration' + '>Click Here</a>' +' to Send Email to Register'));

    return null;

  • 2
    Why don't you want to use query parameters?
    – Phil W
    Commented Sep 10, 2019 at 10:47
  • You can use Platform Cache or store in an Object for this if you really want not to pass anything in the param.
    – Arabinda
    Commented Sep 10, 2019 at 10:57

1 Answer 1


You can use Apex Cookies to pass values between pages. Here's a working demo.

On PageOne, whatever value user enters in the input box, that value will be stored in greeting cookie and will be retrieved on PageTwo and displayed on the page.

// Page One

<apex:page controller="PageOneCtrl" docType="html-5.0">
            <apex:pageBlockSection collapsible="false" columns="1">
                    <apex:outputLabel>Greeting: </apex:outputLabel>
                    <apex:input type="text" value="{!greeting}" />
                <apex:commandButton value="Set Cookie" action="{!setCookieAndNavigate}" />

// Page One Controller

public class PageOneCtrl {

    public String greeting {get; set;}

    public PageReference setCookieAndNavigate(){
        Cookie c = new Cookie('greeting', greeting, null, -1, false);
        ApexPages.currentPage().setCookies(new Cookie[]{c});
        PageReference pageRef = Page.PageTwo;
        return pageRef;

// Page Two

<apex:page controller="PageTwoCtrl">
    Hello, {!greeting}.

// Page Two Controller

public class PageTwoCtrl {

    public String getGreeting(){
        Cookie greeting = ApexPages.currentPage().getCookies().get('greeting');
        return greeting.getValue();

Hope this helps.

  • Both VF page has same controller. In this case how to read the value and populate the data in input field(on Load).
    – SK2889
    Commented Sep 11, 2019 at 17:27
  • @user3214361 In your original post you have mentioned that your pages use different controllers. Anyways you can try and update your code and @ message me to look into it.
    – jagmohan
    Commented Sep 12, 2019 at 14:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .