+ Start a Discussion
AnjaneyluAnjaneylu 

Passing values from one Visualforce Page to another Visualforce Page/

Hi,
Here i need to pass values from One VF page to another VF page.
In one vf page i have selected some records or values and then i want to pass those values to another page.
So please help me..
Thanks in Advance.
Anji 
Ashish DevAshish Dev
You can send using GET and POST methods, POST is preferred due to varied degree of reasons.
Below is the example for sending values from one page to another using POST.
Please note - For simplicity creating and serializing JSON of Data has not been mentioned. You need to prepare JSON of selected records.

Page1 - Page1SendPost
 
<apex:page controller="Page1SendPostCtrl">
    <form id="browserpost" method="POST" action="Page2RecievePost">
        <input type="hidden" name="payloadbase64" value="{!strInputFld}"/>
        <button type="submit" >
            Post Submit
        </button>        
    </form>
</apex:page>


Page1SendPostCtrl
 
public class Page1SendPostCtrl {
    public string strInputFld {set;}
    
    public string getStrInputFld(){
        return 'test is for post send and receive';
    }
    public PageReference redPost(){
        PageReference rPost = Page.Page2RecievePost;
        rPost.setRedirect(true);
        return rPost;
    }
}

Page2RecievePost
 
<apex:page >
    <apex:form >
    	this what we get from POST request -
        "{!$CurrentPage.parameters.payloadbase64}"
    </apex:form>
</apex:page>

Select this as best answer for others to help if it solved your problem.
 
Amit Chaudhary 8Amit Chaudhary 8
There are two way to do this.
1) Create one controller for both VF page
2) We can pass the value in URL
AnjaneyluAnjaneylu
Thank you Amit and Ashish.
Here i need to send more recoreds or values .
So through  URL it is complicated i think so. 
is it ?
Can you tell me the code with the first method.

Thanks in advance.
Anji
Amit Chaudhary 8Amit Chaudhary 8
Please check below post for same.
http://cmlohani-force.blogspot.in/2012/06/single-controller-for-multiple.html

Please let us know if this will help you.

Thanks
Amit Chaudhary
Antonio ManenteAntonio Manente
Putting values in the URL is not difficult, but there are considerations to think about when taking this approach. Here's an example of how it'd be done though..
public PageReference newPage(){
    PageReference newPage = Page.YOUR_PAGE_NAME || new PageReference('/apex/YOUR_PAGE_NAME');     
    newPage.getParameters().put(VARIABLE_NAME, VALUE); 
    newPage.setRedirect(true); 
    return newPage;
}


 
Bushra Salman 6Bushra Salman 6
https://forcefixes.blogspot.com/2018/01/the-vf-page-would-be-like-this-idform.html


this might be helpful
Rupa NRupa N
Hi,

I have 2 visualforce pages and one controller, Visualforce page 1 has  one field and Visualforce page 2 has 4 fields. My question is,  how can I  capture the value from that field on  page1 and pass that value to particular field on page 2. Can this be done? Please let me know.



Here is my code:

I want to get the value from pg1 to get displayed in pg2 in the field current_Maturities_Long_Term_Debt_RUS__c.

How do I get it? need help ASAP.

Visualforce Page1:

<apex:page standardController="RUS_Debt__c" standardController="Sample1">
<apex:form>
  <apex:pageBlock>
    <apex:pageBlockButtons>
         <apex:CommandButton value="Save" action="{!Save}" rendered="true"/>
   </apex:pageBlockButtons>
   <apex:pageBlockSection>
       <apex:outputField value={!RUS_Debt__c.Current_Maturities_Ltd__c}"/>
    </apex:pageBlockSection>
   </apex:pageBlock>
   </apex:form>
  </apex:page>



Visualforce Page2:

<apex:page standardController="Liabilities_And_Equity__c" extensions="Sample1">
<apex:form>
   <apex:pageBlock>
   <apex:pageBlockButtons>
        <apex:commandButton value="Save" action="{!Save}" />
  </apex:pageBlockButtons>
<apex:pageBlockSection>
  <apex:inputfield value="{!Liabilities_And_Equity__c.Accounts_Payable_Affiliates__c}" />
  <apex:inputfield value="{!Liabilities_And_Equity__c.current_Maturities_Long_Term_Debt_RUS__c}"/>

</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>



Controller:

public class Sample1{

  public RUS_Debt__c rdobj {get; private set;}

public Sample1(ApexPages.StandardController stdcntlr){

}
public PageReference Save() {

  PageReference pgref = new PageReference('/apex/BSTestForm');
rdobj =Apexpages.currentpage().getParameters().get('id');
pgref.setRedirect(false);
return pgref;

}
}

     
Thanks.
 Rupa.