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
Devaraj 7Devaraj 7 

How to create 10 account s and each account have 50 orders ,

Ajay K DubediAjay K Dubedi
Hi Devaraj,

You can use this example to create 10 account s and each account have 50 orders:
 
public class AccountCreated {
    public static void createAccount()
    {
        Integer i;
        Integer k;
        List<Account> accList = new List<Account>();
        List<Order> orderList = new List<Order>();
        for(i=1; i<=10; i++)
        {
            Account accObject = new Account(Name='Account'+i);
            accObject.Name = 'cde' + i;
            accList.add(accObject);
            system.debug('accList----->'+accList);
        }
        insert accList;
        for(Account acc : accList)
        {
            for(k =1; k<=5; k++)
            {
                Order orderObject = new Order();
                orderObject.Name = 'abc'+ k;
                orderObject.AccountId = acc.Id;
                orderObject.EffectiveDate = Date.today();
                orderObject.Status = 'Draft';
                orderList.add(orderObject);
            }
            system.debug('orderList----->'+orderList); 
        }
        
        insert orderList;
    }
}


I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks,
Ajay Dubedi