While trying to add multiple records on my Custom object Book using standard Controller and extension . While clicking on the submit button records are not inserted . Could you please check at my extension Logic and do the needful !! Even my User Interface is not showing the name field is required . (I mean Book Name )
Visual Force Page
<apex:page sidebar="false" standardController="Book__c" extensions="addMultipleBooksExtension">
<apex:form id="formId">
<apex:pageBlock >
<apex:pageBlockSection >
<apex:inputField value="{!Book__c.Name}" />
<apex:inputField value="{!Book__c.Title__c}"/>
<apex:inputField value="{!Book__c.Author__c}"/>
<apex:inputField value="{!Book__c.Price__c}"/>
</apex:pageBlockSection>
</apex:pageBlock>
<apex:commandButton value="Add one more Book" action="{!addBook}" />
<apex:commandButton value="Save your Records" action="{!saveBookRecords}"/>
</apex:form>
</apex:page>
Page Extension
public with sharing 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(){
Book__c book= new Book__c() ;
listBook = new list<BooK__c>();
listBook.add(book);
}
public PageReference saveBookRecords(){
listBook = new list<Book__c>();
Integer i ;
for (i=0 ; i < listBook.size();i++){
insert listBook;
}
return null;
}
}