You need to sign in to do that
Don't have an account?
Khaja Basheer
related records insert for loop
Hi all. Im trying to insert some account records and also its related case and opportunity records. I wrote the below code but it is throwing an error as ' Expecting '}' but was: '<EOF>'
can any one point the mistake in the code please ?
#Apex
Accounnt acc = new Account();
acc.name = 'Samurai';
acc.employees = 20;
insert acc;
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;
insert cs;
if ( cs.id !=null){
system.debug (cs.id);
for (integer counter = 1; counter <=5; counter++){
Opportunity opp = new Opportunity ();
opp.Name = 'Salman';
opp.closedate = system.today();
opp.stage = 'prospecting';
opp.accountid=opp.id;
insert opp;
if (opp.id!=null){
system.debug(opp.id);
}
}
}
}
can any one point the mistake in the code please ?
#Apex
Accounnt acc = new Account();
acc.name = 'Samurai';
acc.employees = 20;
insert acc;
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;
insert cs;
if ( cs.id !=null){
system.debug (cs.id);
for (integer counter = 1; counter <=5; counter++){
Opportunity opp = new Opportunity ();
opp.Name = 'Salman';
opp.closedate = system.today();
opp.stage = 'prospecting';
opp.accountid=opp.id;
insert opp;
if (opp.id!=null){
system.debug(opp.id);
}
}
}
}
Hi,
Please use this standard code.
Please mark it as the Best Answer so that other people would take references from it.
Thank You
All Answers
Please change the code as below. You should add '}' at the end and also you are assiging case id to accountid which is wrong. I have modified the code as below and it worked.
If this solution helps, Please mark it as best answer.
Thanks,
Hi,
Please use this standard code.
Please mark it as the Best Answer so that other people would take references from it.
Thank You
Please use below code:-
if you need any assistanse, Please let me know!!
Kindly mark my solution as the best answer if it helps you.
Thanks
Mukesh