A common use case for Visualforce is to present a list of sObjects, allowing a user to select a number of these, and then choose an action to apply to the selected entries. Marking an sObject entry as selected presents a challenge, as it is associating transient information, the selected status, with a record persisted in the Salesforce database.
The solution is to use a wrapper class to encapsulate or wrap an sObject instance and some additional information associated with the sObject instance.
In this recipe, we will create a Visualforce page that presents a list of opportunity sObjects, and allows the user to select a number of records to remove from the displayed list.
This recipe makes use of a wrapper class which associates a checkbox with an opportunity sObject record.
Navigate to the Apex Classes setup page by clicking on Your Name | Setup | Develop | Apex Classes.
Click on the New button.
Paste the contents of the
SelectOpportunityWrapper.cls
Apex class...