0

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

VF

<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>
          <apex:column headervalue="account site" width="20" >
            <apex:inputField value="{!a.site}" required="true"/>
          </apex:column>
          <apex:column headervalue="account phone" width="20" >
            <apex:inputField value="{!a.phone}" required="true"/> 
          </apex:column>
        </apex:dataTable> 
      </apex:pageBlockSection>
      <apex:pageblockButtons >
        <apex:commandButton value="save" action="{!insertNewItem}" immediate="true" />
      </apex:pageblockButtons>
    </apex:pageBlock>
  </apex:form>
</apex:page>

apex

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();
            acc.add(ac);
        }
    }

    public PageReference insertNewItem() {
        insert acc;
        system.debug('<<<<<<<<<<<<'+acc);
        acc= new list<account>();
        /*
        for(integer i=0 ; i<3 ;i++){
            account ac = new account();
            acc.add(ac);}
        */
        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. – Willem Mulder Sep 25 '15 at 12:24
0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.