You need to sign in to do that
Don't have an account?
Waqar Hussain SF
how to add a new row in vf page. I am not getting properly. what is missing?
This is my page..
<apex:page standardController="Employee__c" extensions="recordExt">
<apex:form>
<apex:pageBlock title="Employee Records">
<apex:messages/>
<apex:pageBlockButtons>
<apex:commandButton value="Save" action="{!mySave}"/>
<apex:commandButton value="Cancel"/>
</apex:pageBlockButtons>
<apex:pageBlockSection>
<apex:pageBlockTable value="{!employee__c}" var="e" >
<apex:column headerValue="Employee Name">
<apex:inputField value="{!e.Name}"/>
</apex:column>
<apex:column headerValue="Last Name">
<apex:inputField value="{!e.Last_Name__c}"/>
</apex:column>
<apex:column headerValue="Joining Date">
<apex:inputField value="{!e.Join_Date__c}"/>
</apex:column>
<apex:column headerValue="City">
<apex:inputField value="{!e.City__c}"/>
</apex:column>
<apex:column headerValue="Phone">
<apex:inputField value="{!e.phone__c}"/>
</apex:column>
<apex:column>
<apex:commandButton value="+" action="{!add}"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
and here is my controller.
public class recordExt {
public Employee__c emp {get; set;}
public List<Employee__c> empList {get; set;}
public static Integer addCount {get; set;}
public recordExt(ApexPages.StandardController controller) {
this.emp = (Employee__c)Controller.getRecord();
empList = new List<employee__c>();
}
public void add() {
empList.add(new employee__c());
//this.empList = new List<employee__c>();
}
public pageReference mySave() {
try{
insert emp;
}
catch(Exception ex){
ApexPages.addmessages(ex);
}
return null;
}
}
<apex:page standardController="Employee__c" extensions="recordExt">
<apex:form>
<apex:pageBlock title="Employee Records">
<apex:messages/>
<apex:pageBlockButtons>
<apex:commandButton value="Save" action="{!mySave}"/>
<apex:commandButton value="Cancel"/>
</apex:pageBlockButtons>
<apex:pageBlockSection>
<apex:pageBlockTable value="{!employee__c}" var="e" >
<apex:column headerValue="Employee Name">
<apex:inputField value="{!e.Name}"/>
</apex:column>
<apex:column headerValue="Last Name">
<apex:inputField value="{!e.Last_Name__c}"/>
</apex:column>
<apex:column headerValue="Joining Date">
<apex:inputField value="{!e.Join_Date__c}"/>
</apex:column>
<apex:column headerValue="City">
<apex:inputField value="{!e.City__c}"/>
</apex:column>
<apex:column headerValue="Phone">
<apex:inputField value="{!e.phone__c}"/>
</apex:column>
<apex:column>
<apex:commandButton value="+" action="{!add}"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
and here is my controller.
public class recordExt {
public Employee__c emp {get; set;}
public List<Employee__c> empList {get; set;}
public static Integer addCount {get; set;}
public recordExt(ApexPages.StandardController controller) {
this.emp = (Employee__c)Controller.getRecord();
empList = new List<employee__c>();
}
public void add() {
empList.add(new employee__c());
//this.empList = new List<employee__c>();
}
public pageReference mySave() {
try{
insert emp;
}
catch(Exception ex){
ApexPages.addmessages(ex);
}
return null;
}
}
<apex:page standardController="Employee__c" extensions="recordExt">
<apex:form>
<apex:pageBlock title="Employee Records">
<apex:messages/>
<apex:pageBlockButtons>
<apex:commandButton value="Save" action="{!mySave}" rerender="employeeSection"/>
<apex:commandButton value="Cancel"/>
</apex:pageBlockButtons>
<apex:pageBlockSection id="employeeSection">
<apex:pageBlockTable value="{!empList}" var="e" >
<apex:column headerValue="Employee Name">
<apex:inputField value="{!e.Name}"/>
</apex:column>
<apex:column headerValue="Last Name">
<apex:inputField value="{!e.Last_Name__c}"/>
</apex:column>
<apex:column headerValue="Joining Date">
<apex:inputField value="{!e.Join_Date__c}"/>
</apex:column>
<apex:column headerValue="City">
<apex:inputField value="{!e.City__c}"/>
</apex:column>
<apex:column headerValue="Phone">
<apex:inputField value="{!e.phone__c}"/>
</apex:column>
<apex:column>
<apex:commandButton value="+" action="{!add}" rerender="employeeSection"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
public class recordExt {
public Employee__c emp {get; set;}
public List<Employee__c> empList {get; set;}
public static Integer addCount {get; set;}
public recordExt(ApexPages.StandardController controller) {
this.emp = (Employee__c)Controller.getRecord();
empList = new List<employee__c>();
}
public void add() {
empList.add(new employee__c());
//this.empList = new List<employee__c>();
}
public pageReference mySave() {
try{
upsert empList;
}
catch(Exception ex){
ApexPages.addmessages(ex);
}
return null;
}
}
All Answers
Thought I am aware of the pitfalls you may be facing, and can maybe see some nuances in your code I might investigate, to save us all time, if you can give a specific problem - I'm sure we will be happy to review it with you!
<apex:page standardController="Employee__c" extensions="recordExt">
<apex:form>
<apex:pageBlock title="Employee Records">
<apex:messages/>
<apex:pageBlockButtons>
<apex:commandButton value="Save" action="{!mySave}" rerender="employeeSection"/>
<apex:commandButton value="Cancel"/>
</apex:pageBlockButtons>
<apex:pageBlockSection id="employeeSection">
<apex:pageBlockTable value="{!empList}" var="e" >
<apex:column headerValue="Employee Name">
<apex:inputField value="{!e.Name}"/>
</apex:column>
<apex:column headerValue="Last Name">
<apex:inputField value="{!e.Last_Name__c}"/>
</apex:column>
<apex:column headerValue="Joining Date">
<apex:inputField value="{!e.Join_Date__c}"/>
</apex:column>
<apex:column headerValue="City">
<apex:inputField value="{!e.City__c}"/>
</apex:column>
<apex:column headerValue="Phone">
<apex:inputField value="{!e.phone__c}"/>
</apex:column>
<apex:column>
<apex:commandButton value="+" action="{!add}" rerender="employeeSection"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
public class recordExt {
public Employee__c emp {get; set;}
public List<Employee__c> empList {get; set;}
public static Integer addCount {get; set;}
public recordExt(ApexPages.StandardController controller) {
this.emp = (Employee__c)Controller.getRecord();
empList = new List<employee__c>();
}
public void add() {
empList.add(new employee__c());
//this.empList = new List<employee__c>();
}
public pageReference mySave() {
try{
upsert empList;
}
catch(Exception ex){
ApexPages.addmessages(ex);
}
return null;
}
}