+ Start a Discussion

help on query string parameters

Hi all



I have a visual force page that consists of two fiels doctor and branch.I also created another visual force page that also contains the same fields branch and doctor .



now how can i populate my second visual force page with the values given in the first visual force page on a button click

Shashikant SharmaShashikant Sharma

Just use same controller class and same properties of the class for both the pages and when you redirect from one page to second page use setRedirect(false) likt this



public PageReference nextpage()
PageReference pg = new PageReference(Page.page2.getUrl());
        return pg;

setRedirect :  If set to false, the redirect is a server-sideforward that preserves the view state if and only if thetarget page uses the same controller and contains the proper subset of extensions used by the source page.



thanks for the reply but the two visual force pages are not using the same controller. in this case how i can i populate the fields of first visual force page on the second

Shashikant SharmaShashikant Sharma

Pass the id's of record in query parameters then, And fetch values of the object in the constructor using SOQL , and display values , thats is the only way.


like this

Setting prameter :


pg.getParameters().put('branchid' , 'yourBranchId');

return pg;


inconstructor of second page

Id BranchId = ApexPages.currentPage().getParameters().get('branchid');

//Fetch all the fields which you want to show

Branch__c b = [Select id from Branch__c where id =: BranchId ];


Similarly you can do it for second object as well.


Hi try this,


from first page, in Button click Action method,

PageReference ref = new pageReference('/apex/secondpage?id='+RecordID);

return ref;


If you're using Standard Controller in your second page use inputField in Page. then it'll populate the Field values.


else get the Id in Controller & Query the Object then sent those values to the page.