Delete particular record in Visualforce table

Delete particular record in Visualforce table

There are scenarios in business environments where there is need to delete a particular record from the list of records displayed on a given table in Visualforce. For example, if there are duplicates records in your Salesforce org, one of the ways to clean the records is to delete the extra.

The table below shows the desired user interface to be achieved

The UI mimics the look and feel of Salesforce list of records in that most records owned by you have the Edit and Del links displayed.

The Visualforce page code is pasted below –

Depending on where you want your Action column to appear,  it can come first or last as shown above.

The custom controller used along with the Visualforce code is attached below

Notice that  <apex:commandlink>  rerender attribute is not used in the Visualforce code. This is because of the way the  List<Bank__c>  property is defined in the Apex code.  Instead of using automatic property whereby you leave the get and set accessor code blocks empty, the get accessor returns the SOQL query needed to display the list of records for the table. If you write the SOQL query in the constructor (it is commented out in the code), the particular record you want to delete will get deleted but the table will not re-render. That means you will have to refresh the table/page manually or use the rerender attribute

Reference

Apex Developer Guide

Visualforce Developer Guide

Leave a Reply

Close Menu