Skip to main content
Khaja Basheer が「#Apex」で質問
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);   

             }     

        }     

    }   

  }     
4 件の回答
  1. 2021年8月24日 6:47

    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

0/9000