Dynamically Add/Remove rows from a table in visualforce

5:31 PM

Screenshot:


The example below illustrates the way to REMOVE any given row in a table in visualforce and ADD new rows.

The REMOVE button only removes the contact from the UI.
The REMOVED rows are deleted from the database when the "SAVE Changes" button is clicked.

To execute this example include a valid Account ID in the URL as below

https://na5.salesforce.com/apex/deleteRowsExample?id=0017000000UIvsg

VF PAGE: deleteRowsExample

Apex Controller: deleteRowsExample

4 comments

  1. I think its better to check if deleteContactList is not null too before checking the size, if deleteContactList is null it can throw null pointer exception on size

    ReplyDelete
    Replies
    1. Not really, DML on null lists is allowed.

      Delete
    2. It can't be null, the deleteContactList list is initialised at the top.

      Delete
  2. Thanks for this! As others suggested, a query string of ?id=[ACCOUNT-ID] needs to be added to the URL.

    ReplyDelete