+ Start a Discussion

Add/Remove for Sublist Items

I'm working off of some code that I found on this blog:

To implement an "Add/Remove" functionality to a visualforce page. The trick is, I'd like to add the add/remove functionality to the Account level as well.

Currently, it is working with Contacts that are related to a single Account and it let's you create a datatable that you can have an add/remove button on each row. I'd like it to be that I can add/remove at the Account level as well. Here is the controller code:
public class addAttendee {
public Account accounts;
 public Contact del;
 public List<Contact> addattendeeList {get;set;}
 public List<Contact> delattendeeList {get;set;}
 public List<Contact> attendeeList {get;set;}
 public Integer totalCount {get;set;}
 public Integer rowIndex {get;set;}
 public List<Contact> delAttendees {get; set;} 
 public addAttendee(ApexPages.StandardController controller) {
 accounts = (Account)controller.getRecord();
 attendeeList = [Select id, firstName, LastName, Email, Phone from Contact where AccountId =: accounts.Id];
 totalCount = attendeeList.size();
 delattendeeList = new List<Contact>();
 delattendees = new List<Contact>();
 public void addRow(){
 addattendeeList = new List<Contact>();
 attendeeList.add(new Contact(AccountId = accounts.Id));
 public PageReference ave(){
 upsert attendeeList;
 delete delattendeeList;
 return (new ApexPages.StandardController(accounts)).view();
 public void deleteRow(){
 rowIndex = Integer.valueOf(ApexPages.currentPage().getParameters().get('rowIndex'));
 System.debug('row to be deleted ' + rowIndex );
 System.debug('row item to be deleted '+attendeeList[rowIndex]);
 del = attendeeList.remove(rowIndex);

ShashankShashank (Salesforce Developers) 
If you are saying that the page should display all accounts on one page so that you can add/remove account records, you just need to query the accounts instead of contacts. Here's an example:

[Select id, firstName, LastName, Email, Phone from account];