• Khaja Basheer
  • NEWBIE
  • 10 Points
  • Member since 2021

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 1
    Replies
Can any one point the mistakes in my code. I'm looking to insert an account record and its related 20 opportunity records and 5 related case records to that account. 

public class AccountHelper {
    
    public static void AccountRecordHelper() {
        
        List<Opportunity> lstopp = New List <opportunity> ();
        List<Case> CaseNew = New List <Case> ();
       
        Account Acc = New Account();
        Acc.Name = 'Gen Construction';
        Acc.Industry= 'Contruction';
        insert acc;
        If (acc.id != Null) {
            
          
            
            for (Integer C = 1; C<=20; C++) {
                Opportunity Opp = New Opportunity ();
                Opp.Name = 'Dean Constructions' + C;
                opp.CloseDate = system.today ();
                opp.StageName = 'Prospecting';
                opp.AccountId = acc.Id;
                lstopp.add(opp);
                insert lstopp;
 
            }
            
            Case Cs = New Case();
            for (integer i = 1; i<=10; i++) {
                
                Cs.Status = 'New';
                Cs.Origin = 'Phone';
                Cs.AccountId = acc.Id;
                casenew.add(cs);
                insert casenew;

            }
            
            
            
            System.debug (lstopp);
            system.debug(casenew);
            system.debug(acc.id);
            
        } 
    }

}
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);   
             }     
        }     
    }   
  }     
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);   
             }     
        }     
    }   
  }