Skip to main content
deleted 10 characters in body
Source Link
sfdcfox
  • 501.6k
  • 21
  • 473
  • 828

You're clearing the list each time you add a new book, and your save method also creates a new list, which wipes out the previous work; it causes all the input to be lost.

Here's a working version of your controller:

public class addMultipleBooksExtension {
    public list<Book__c> listBook{get;set;}

    public addMultipleBooksExtension(ApexPages.StandardController controller) {
    list<Book__c>    listBook= new list<Book__c>();
    }

  public void addBook(){
      listBook.add(new Book__c());
  }

  public void saveBookRecords(){
    upsert listBook;
  }
}

You're clearing the list each time you add a new book, and your save method also creates a new list, which wipes out the previous work; it causes all the input to be lost.

Here's a working version of your controller:

public class addMultipleBooksExtension {
    public list<Book__c> listBook{get;set;}

    public addMultipleBooksExtension(ApexPages.StandardController controller) {
    list<Book__c> listBook= new list<Book__c>();
    }

  public void addBook(){
      listBook.add(new Book__c());
  }

  public void saveBookRecords(){
    upsert listBook;
  }
}

You're clearing the list each time you add a new book, and your save method also creates a new list, which wipes out the previous work; it causes all the input to be lost.

Here's a working version of your controller:

public class addMultipleBooksExtension {
    public list<Book__c> listBook{get;set;}

    public addMultipleBooksExtension(ApexPages.StandardController controller) {
        listBook= new list<Book__c>();
    }

  public void addBook(){
      listBook.add(new Book__c());
  }

  public void saveBookRecords(){
    upsert listBook;
  }
}
edited body
Source Link
sfdcfox
  • 501.6k
  • 21
  • 473
  • 828

You're clearing the list each time you add a new book, and your save method also creates a new list, which wipes out the previous work; it causes all the input to be lost.

Here's a working version of your controller:

public class addMultipleBooksExtension {
    public list<Book__c> listBook{get;set;}

    public addMultipleBooksExtension(ApexPages.StandardController controller) {
    list<Book__c> listBook= new list<Book__c>();
    }

  public void addBook(){
      listBook.add(new Book__c());
  }

  public void saveBookRecords(){
    insertupsert listBook;
  }
}

You're clearing the list each time you add a new book, and your save method also creates a new list, which wipes out the previous work; it causes all the input to be lost.

Here's a working version of your controller:

public class addMultipleBooksExtension {
    public list<Book__c> listBook{get;set;}

    public addMultipleBooksExtension(ApexPages.StandardController controller) {
    list<Book__c> listBook= new list<Book__c>();
    }

  public void addBook(){
      listBook.add(new Book__c());
  }

  public void saveBookRecords(){
    insert listBook;
  }
}

You're clearing the list each time you add a new book, and your save method also creates a new list, which wipes out the previous work; it causes all the input to be lost.

Here's a working version of your controller:

public class addMultipleBooksExtension {
    public list<Book__c> listBook{get;set;}

    public addMultipleBooksExtension(ApexPages.StandardController controller) {
    list<Book__c> listBook= new list<Book__c>();
    }

  public void addBook(){
      listBook.add(new Book__c());
  }

  public void saveBookRecords(){
    upsert listBook;
  }
}
Source Link
sfdcfox
  • 501.6k
  • 21
  • 473
  • 828

You're clearing the list each time you add a new book, and your save method also creates a new list, which wipes out the previous work; it causes all the input to be lost.

Here's a working version of your controller:

public class addMultipleBooksExtension {
    public list<Book__c> listBook{get;set;}

    public addMultipleBooksExtension(ApexPages.StandardController controller) {
    list<Book__c> listBook= new list<Book__c>();
    }

  public void addBook(){
      listBook.add(new Book__c());
  }

  public void saveBookRecords(){
    insert listBook;
  }
}