I tried to create account records using datable.Its worked fine when the command button is .But using immediate button in the command button (i.e)its not working


<apex:page controller="accountcontroller">
  <apex:form >
    <apex:pageBlock >
      <apex:pageBlockSection >
        <apex:dataTable value="{!acc}"   var="a" cellpadding="4" border="1" rows="3" >
          <apex:column headervalue="account name" width="20" >
            <apex:inputField value="{!a.name}" required="true"/> 
          <apex:column headervalue="account site" width="20" >
            <apex:inputField value="{!a.site}" required="true"/>
          <apex:column headervalue="account phone" width="20" >
            <apex:inputField value="{!a.phone}" required="true"/> 
      <apex:pageblockButtons >
        <apex:commandButton value="save" action="{!insertNewItem}" immediate="true" />


public class accountcontroller {
    public list<account> acc{get;set;}

    public accountcontroller(){
        acc= new list<account>();
        for ( integer i = 0 ; i < 3 ;i++ ) {
            account ac = new account();

    public PageReference insertNewItem() {
        insert acc;
        acc= new list<account>();
        for(integer i=0 ; i<3 ;i++){
            account ac = new account();
        return null;

  • Apart from the english (which I assume you can't help) it would really help if you'd structure your question more. What is the goal, what is the actual, specific, problem and what have you tried yourself? Also, the formatting of code... Did you actually read the FAQ? I can't help you like this. Sep 25, 2015 at 12:24

1 Answer 1


I think you want to insert the list of accounts after pressing the command button. so, may be problem here is you are not giving the values to the required fields of an account, without giving values to the required field new account can not be inserted as immediate attribute only bypasses the validation rules.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .