function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
suresh dupadasuresh dupada 

How to pass values from one VFpage to another VFpage

Here I am trying to pass id value from first page (pageonepagetwo) to another page (pagetwo), by clicking the button in page one i want to pass the id value to the pagetwo, in pagetwo i am having the table, this table need to display the contacts based on the account id

page one:(pageonepagetwo)

<apex:page controller="PageOne">
<apex:form > 
  <apex:pageblock >
        <apex:pageblocksection >
            <apex:commandButton value="Show Table" action="{!showTable}"/>
           
        </apex:pageblocksection>
    </apex:pageblock>
</apex:form>
</apex:page>

******controller*******
public class PageOne
{
    public void showTable()
    {
    PageReference pr;
    pr = Page.pagetwo; // use the name of the second VF page
    pr.setRedirect(true);
    pr.getParameters().put('id','00190000015yBQ6');
    }
}


Second two: (pagetwo)

<apex:page controller="Secondtwo">
    <apex:pageblock title="TableData Based on another page">
        <apex:pageblocktable value="{!TableData}" var="data">
            <apex:column >{!data.name}</apex:column>
        </apex:pageblocktable>
    </apex:pageblock>
</apex:page>
******** controller***************
public class Secondtwo
{
    public list<contact> TableData{set;get;}
    public Secondtwo()
    {
        TableData=[select name from contact where accountid=:ApexPages.currentPage().getParameters().get('id')];  
    }
}

Best Answer chosen by suresh dupada
kannapapikannapapi
Change ur PageOne controller like this..

public class PageOne
{
    public PageReference showTable()
    {
PageReference url=new PageReference('/apex/pagetwo?id=00190000015yBQ6');
                 return url;
    }
}

All Answers

bob_buzzardbob_buzzard
I can't see anything obviously wrong with your code.  I assume you are having a problem?  Care to share the details with us?
kannapapikannapapi
Change ur PageOne controller like this..

public class PageOne
{
    public PageReference showTable()
    {
PageReference url=new PageReference('/apex/pagetwo?id=00190000015yBQ6');
                 return url;
    }
}
This was selected as the best answer