Visualforce Example – Mass update records

One of the greatest examples of the implementation of Visualforce will be a mass update of records. In this example, we will create pages that can perform mass updates. It will use the prototype object contained in the StandardSetController class.

The objective of this example

Here we will use a list controller, which will track two sets of records:

  • A primary list that will have all the records selected by the filter
  • A secondary list containing those records the user selected.

The secondary list is created on a standard listview page where a particular user can checkboxes to select the records. The user can then click on a custom list button that navigates to the custom mass update page, which will ideally use the prototype object to apply new field values to the user’s selection. The prototype object operates on all the records in the user’s selection. To retrieve the prototype object within the custom controller, use the StandardSetController’s “getRecord” method.

Implementing this example

We can implement this solution with the steps listed below.

  • Create a Visualforce page called massupdatestages.
  • Provide the following controller
  • In the next step, code the markup as shown below.
  • In the next step, go to object management settings for opportunities,
  • Go to Buttons -> Links -> Actions.
  • Click on New Button or Link.
  • Set the Button Label to “Mass Update Stages“, and set the Name to “MassUpdateStages“.
  • Now set the Display Type to List Button (ensure that Display Checkboxes (for Multi-Record Selection) is checked).
  • Set the Behavior to Display in the existing window with the sidebar
  • Set the Content Source to Visualforce Page.
  • Click the name of the page you have created just now so that it can be associated with this button.
  • Click on Save.
  • Now go back to the object management settings for opportunities, then go to Search Layouts. Then click on Edit (It will be located next to Opportunities List View).
  • Under Custom Buttons, move the Mass Update Stages button to the Selected Buttons list.
  • Click on Save.
  • Now, click on the Opportunities tab.
  • Select or create a filter that will show existing opportunities that could be changed.
  • We will see checkboxes next to each of the results.
  • Click any number of checkboxes and click the Mass Update Stages button to change the selected stages to any value you wish.
  • Click on Save.

We can update any number of fields using the functionality shown in this demonstration.

Scroll to Top