+ Start a Discussion

Table saves only each current custom input record. How to save all records?

I am very new to SalesForce and I need help about the following situation: 
I have a form with some input fields about a custom object called Student, like name, Surname etc. On the same page below I have another form with a table and I want this table to save every single input record from the form above. What I managed to do is when I hit the button Save every current record is being saved in the table and not all records. 

I do not know how to proceed. Any help would be greatly appreciated!

VisualForce code: 

<apex:page controller="StudentController1">
 <apex:form id="form1">
  <apex:pageBlock title="Nov Student">
    <apex:pageBlockSection columns="1">
      <apex:inputField value="{!Student.Name}"/>
      <apex:inputField value="{!Student.Priimek__c}"/>
      <apex:inputField value="{!Student.Letnik__c}"/>
      <apex:inputField value="{!Student.Naslov__c}"/>
      <apex:inputField value="{!Student.Datum_rojstva__c}"/>
      <apex:inputField value="{!Student.Naziv_fakultete__c}"/>
      <apex:inputField value="{!Student.Studijski_program__c}"/>
      <apex:inputField value="{!Student.Tip_studija__c}"/>
<apex:selectcheckboxes layout="pagedirection">
      <apex:selectOption id="Placnik" itemValue="Samoplacnik" itemLabel="Samoplacnik" />

     <apex:pageBlock title="Vsi studenti">
      <apex:pageBlockTable value="{!Student}" var="wrapper" id="wtable" rows="9">
            <apex:column value="{!wrapper.Name}"/>      
            <apex:column value="{!wrapper.Priimek__c}"/>
            <apex:column value="{!wrapper.Naslov__c}"/>
            <apex:column value="{!wrapper.Datum_rojstva__c}"/>      
            <apex:column value="{!wrapper.Naziv_fakultete__c}"/>
            <apex:column value="{!wrapper.Studijski_program__c}"/>
            <apex:column value="{!wrapper.Letnik__c}"/>
            <apex:column value="{!wrapper.Tip_studija__c}"/>
 <apex:commandButton action="{!dodajStudent}" value="Save" id="theButton" reRender="wtable"/>

APEX code:

public class StudentController1 {

  public boolean showValue {get;set;}
  public string studentName {get;set;}
  public Student__c student {get;set;}
  public StudentController1(){
        student = new Student__c();
  public pageReference Save(){
        insert student; 
        return null;
  public void dodajStudent(){
        upsert student;
  public void updateFieldVisibility() {
        showValue = true;
In Controller:
1. Create a list of Student__c object. This list will store the records you have created in table 1.
2. Iterate over that list in table 2 to show the records you created.
3. Put some button (like add) to add the new record created in table 1 to the list of Student__c object.
4. Once you are done creating records. Click on save and insert the list of Student__c records list.

Following example shows the same for Contact object:
Visualforce Page:
<apex:page controller="AddContactsController">
    <apex:form id="form1">
        <apex:pageBlock title="Contact">
            <apex:commandButton action="{!add}" value="Add" rerender="results"/>
            <apex:pageBlockSection columns="1">
                <apex:inputField value="{!con.FirstName}"/>
                <apex:inputField value="{!con.Lastname}"/>
            <apex:pageBlockTable value="{!contacts}" var="record" id="results">
                <apex:column value="{!record.Firstname}"/>      
                <apex:column value="{!record.Lastname}"/>
            <apex:commandButton action="{!saveRecords}" value="Save"/>

public class AddContactsController {
    public Contact con {get;set;}
    public List<Contact> contacts {get;set;}
    public AddContactsController(){
        contacts = new List<Contact>();
        con = new Contact();
    public PageReference add(){
        con = new Contact();
        return null;
    public PageReference saveRecords(){
        insert contacts; 
        return null;