function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Devang Rana 6Devang Rana 6 

Problem in Mass Installation.. If i store one Value then there is no problem but when i store more then on record then it will show me error

public class AddmultipleAccountsController {
User-added image            Account account = new Account();
                      public list<Account> listAccount{ get; set; }

                  public AddmultipleAccountsController() 
                         {
                           listAccount=new list<Account>();
                           listAccount.add(Account);
                         }
                                    
                    Public void addAccount()
                          { 
                             Account acc = new Account();
                             listAccount.add(acc);                        
                          }
                          
                    public PageReference saveAccount() 
                    {
                         for(Integer i=0; i<listAccount.size(); i++)
                            {
                            insert listAccount;
                            }
                       return Page.Allaccountssaved;    
                }
}
Best Answer chosen by Devang Rana 6
Deepak GulianDeepak Gulian
public class AddmultipleAccountsController {

Account account = new Account();
                      public list<Account> listAccount{ get; set; }

                  public AddmultipleAccountsController()
                         {
                           listAccount=new list<Account>();
                           listAccount.add(Account);
                         }
                                    
                    Public void addAccount()
                          {
                             Account acc = new Account();
                             listAccount.add(acc);                        
                          }
                          
                    public PageReference saveAccount()
                    {
                         if(listAccount.size() > 0)
                          insert listAccount;
                       return Page.Allaccountssaved;    
                }
}

I just test this controller and its working fine! Try this

All Answers

Deepak GulianDeepak Gulian
Change in Save Method

public PageReference saveAccount() {
       If(listAccount.size() > 0) {
               insert listAccount;
       }
       return Page.Allaccountssaved;    
 }
Devang Rana 6Devang Rana 6
Hi Deepak

   still it is not working. showing me a same error.
Deepak GulianDeepak Gulian
Share your VF page code also
Devang Rana 6Devang Rana 6
<apex:page Controller="AddmultipleAccountsController">
<apex:form >
<apex:pageBlock >
<apex:pageBlockTable value="{!listAccount}" var="acc">
<apex:column headerValue="Account Name">
<apex:inputField value="{!acc.Name}"/>
</apex:column>
<apex:column headerValue="Account Number">
<apex:inputField value="{!acc.AccountNumber}"/>
</apex:column>
<apex:column headerValue="Account Type">
<apex:inputField value="{!acc.Type}"/>
</apex:column>
<apex:column headerValue="Industry">
<apex:inputField value="{!acc.Industry}"/>
</apex:column>
</apex:pageBlockTable>
<apex:pageBlockButtons >
<apex:commandButton value="Add Accounts Row" action="{!addAccount}"/>
<apex:commandButton value="Save Accounts" action="{!saveAccount}"/>
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>
 
Deepak GulianDeepak Gulian
public class AddmultipleAccountsController {

Account account = new Account();
                      public list<Account> listAccount{ get; set; }

                  public AddmultipleAccountsController()
                         {
                           listAccount=new list<Account>();
                           listAccount.add(Account);
                         }
                                    
                    Public void addAccount()
                          {
                             Account acc = new Account();
                             listAccount.add(acc);                        
                          }
                          
                    public PageReference saveAccount()
                    {
                         if(listAccount.size() > 0)
                          insert listAccount;
                       return Page.Allaccountssaved;    
                }
}

I just test this controller and its working fine! Try this
This was selected as the best answer
Devang Rana 6Devang Rana 6
Thanks For your Help Mr.Deepak