It's just a simple question I'm having(It might sound silly but I've no idea how do I insert 40000 records).
I'm first creating 200 Accounts and also creating 200 child Opportunities for each Account. Can Someone suggest to me how do I achieve it? I think it can be done using BatchApex but I've no idea how to code for that. Below is what I'm trying to do:public class TestOpp {
public static void accwithOpp(){
List<Account> createdAccount = new List<Account>();
List<Opportunity> createdOopp = new List<Opportunity>();
for(Integer i=1;i<=200;i++){
Account a = new Account(Name='TestMebyClass'+i);
createdAccount.add(a);
}
insert createdAccount;
List<Account> ParentAccIds = [SELECT Id FROM Account WHERE Id IN :createdAccount];
for(Account a : ParentAccIds){
for(Integer i=1;i<=200;i++){
Opportunity op = new Opportunity(Name='TestofParentAcc'+i,
StageName='Prospecting',
CloseDate=System.today().addmonths(1),
AccountId=a.Id);
createdOopp.add(op);
}
}
insert createdOopp;
}
}