
Hi,
Please use this standard code.
Accounnt acc = new Account();
acc.name = 'Samurai';
acc.employees = 20;
insert acc;
List<Case> caseList=new List<Case>();
List<Opportunity> OpportunityList=new List<Opportunity>();
if (acc.id != null){
system.debug(acc.id);
for (integer counter = 1 ; counter <= 5; counter++) {
case cs = new case ();
cs.origin = 'Phone';
cs.status = 'high';
cs.accountid = cs.id;
caseList.add(cs);
}
insert caseList;
for(Integer i=0;i<5;i++){
if(caseList[i].Id !=null){
Opportunity opp = new Opportunity ();
opp.Name = 'Salman';
opp.closedate = system.today();
opp.stage = 'prospecting';
opp.accountid=acc.id;
OpportunityList.add(opp);
}
}
insert OpportunityList;
}
Please mark it as the Best Answer so that other people would take references from it.
Thank You