function readOnly(count){ }
Don't have an account?
Search for an answer or ask a question of the zone or Customer Support.
You need to sign in to do that
Sign in to start searching questions
Signup for a Developer Edition
Sign in to start a discussion
<apex:page Controller="AddmultipleAccountsController"> <apex:form > <apex:pageBlock > <apex:outputText value="Accounts Saved" rendered="{!msgForUser}" style="color:red;"/> <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 New Row" action="{!addAccount}"/> <apex:commandButton value="Account Save" action="{!saveAccount}"/> </apex:pageBlockButtons> </apex:pageBlock> </apex:form> </apex:page>
public class AddmultipleAccountsController { Account account = new Account(); public list<Account> listAccount{ get; set;} public List<Account> insrtAccLst = new List<Account>(); public boolean msgForUser{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++){ insrtAccLst.add(listAccount[i]); } msgForUser = true; insert insrtAccLst; return null; } }
public class AccountService { public void createAccountWithContact () { Account account = new Account (Name = 'Test Account'); insert account; List<Contact> contactList = new List<Contact>(); for(Integer i = 0 ; i < 10 ; i++){ Contact contact = new Contact (LastName = 'Test' + String.valueOf(i), AccountId = account.Id, Email = 'testEmail' + String.valueOf(i) + '@test.com'); contactList.add(contact); } insert contactList; } }
May I suggest you please find the sample code below for accounts, and tweak it as per the requirement.
Visual Force Page: ApexClass: Hope this helps.
Thanks,
Nagendra
Please try this simple code and it will surely work:
Account a=new Account();
a.name='New created account';
insert a;
Integer i;
List<Contact> conList=new List<Contact>();
for(i=1;i<=10;i++)
{
Contact c=new Contact();
c.lastname='Contact'+i;
c.accountid=a.id;
conList.add(c);
}
insert conList;
I hope this solution will help you. Mark it as best answer if it helps.
Thanks.
Ajay Dubedi