Display selected records of one Visualforce page on another

Display selected records of one Visualforce page on another

The issue of not being able to display selected records or values of one Visualforce page on another confronting some developers moved to create this post.

To resolve this issue, I created a wrapper class to generate the table with checkboxes. I created a two-step wizard that will allow users to select the desired records on the first page and display them on the second. If you are not familiar with creating Visualforce wizard, you can look forward to my post on the topic or click here to learn more.

For the wizard, I created 2 Visualforce pages that I named selectedBankPage and selectedBankPage2 respectively. These pages are used in the step1 and step2 methods in the Apex code below which in turn were invoked on the Visualforce pages for navigation.

Note, if you create the first page and fail to create the second, there will be an error message prompting you to create the required page.

The selectedBankPage output will look like this



The second page – selelctedBankPage2’s user interface will look like this


The Controller

The Visualforce code for the main page

Things to note in the Visualforce code:

  1. Select and Next button
  2. Save and New button

The Select & Next button

This button performs two actions – processes the selection of records and navigates to the next page. In the Apex code, the two methods – selectedRecords() and step2() are combined for a better user experience (UX) because it will not be in the best interest of the users to click two buttons before getting desired results.

Save And New button

The saveAndNew method is used to clear the field after you save the records. If you invoke only save method, the records saved still populate the fields.

Visualforce Code for the Second page 

This VIsualforce code displays the records selected on the first page by invoking the selectedBanks list.

For example, after selecting 3 records and clicking Select & Next button, this second page will now look like this


The Monthly Earnings field displayed above was added to the SOQL query for the purpose of adding more field(s) to the second page. This is not displayed on the first page.

Leave a Reply

Close Menu