You need to sign in to do that
Don't have an account?

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:selectcheckboxes>
<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:pageBlockTable>
</apex:pageBlock>
<apex:commandButton action="{!dodajStudent}" value="Save" id="theButton" reRender="wtable"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
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;
}
}
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:selectcheckboxes>
<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:pageBlockTable>
</apex:pageBlock>
<apex:commandButton action="{!dodajStudent}" value="Save" id="theButton" reRender="wtable"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
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;
}
}
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: