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
list<Account> acclist = new list<Account>(); for(integer i=1; i<5; i++){ Account objacc = new Account(Name = 'ABC' + i); acclist.add(objacc); } insert acclist; list<Contact> conlist = new list<Contact>(); for(Account objacc :acclist){ Contact objcontact = new Contact(); objcontact.AccountId = objacc.id; objcontact.LastName = objacc.Name; conlist.add(objcontact); } insert conlist;
public class AccountRelatedContacts{ publis static void insertRecords(integer numRec){ list<Account> acclist = new list<Account>(); for(integer i=1; i<=numRec; i++){ Account objacc = new Account(Name = 'ABC' + i); acclist.add(objacc); } insert acclist; list<Contact> conlist = new list<Contact>(); for(Account objacc :acclist){ Contact objcontact = new Contact(); objcontact.AccountId = objacc.id; objcontact.LastName = objacc.Name; conlist.add(objcontact); } insert conlist; } }
public class createAccAndCon{ public static void demoFun(){ List<Account> accList = new List<Account>(); List<Contact> conList = new List<Contact>(); for(Integer i = 0; i<5; i++){ Account acc = new Account(); acc.Name = 'Test' + i; accList.add(acc); } insert accList; for(Account acc : accList){ Contact con = new Contact(); con.LastName = 'con test'; con.AccountId = acc.Id; conList.add(con); } insert conList; } }
Please mark it as best answer if it helps.Thanks,
Please try the below code.
Please mark it as Best Answer if the above information was helpful.
Thanks.
Try Below Code
Please Mark it As Best Answer if it Helps
Thank you!
Try Below Code
Please mark it as best answer if it helps.
Thanks,