• Neha Raizada!
  • NEWBIE
  • 0 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
Hello Dev Community,

We are getting the following error for the APEX Trigger code below:

"Error: Compile Error: unexpected token: '{' at line 35 column 64"

We are trying to iterate over a custom object "Project" and add child objects records "Milestones" based on the value of certain fields in the "Project" related object "Opportunity". I think there may be something wrong with the FOR loop syntax? Any help would be appreciated!
 
Trigger newMilestone on MPM4_BASE__Milestone1_Project__c (before insert){

    List<MPM4_BASE__Milestone1_Project__c> mileProj = [SELECT Id FROM MPM4_BASE__Milestone1_Project__c WHERE MPM4_BASE__Status__c='Set'];
    List<MPM4_BASE__Milestone1_Milestone__c> miles = new List<MPM4_BASE__Milestone1_Milestone__c>();
    
    for (MPM4_BASE__Milestone1_Project__c p : mileProj){
        if (p.Opportunity__r.OrderHardware__c == TRUE) {
            MPM4_BASE__Milestone1_Milestone__c morder = new MPM4_BASE__Milestone1_Milestone__c();
            morder.MPM4_BASE__Project__c = p.Id;
            morder.Name = 'Order Hardware';
            morder.MPM4_BASE__Kickoff__c = date.today();
            morder.OwnerId = '0051a000000STEt';
            miles.add(morder);
        }    else if (p.Opportunity__r.SchedulePSG__c == TRUE) {
                MPM4_BASE__Milestone1_Milestone__c porder = new MPM4_BASE__Milestone1_Milestone__c();
                porder.MPM4_BASE__Project__c = p.Id;
                porder.Name = 'Schedule PSG';
                porder.MPM4_BASE__Kickoff__c = date.today();
                porder.OwnerId = '0051a000000R80f';
                miles.add(porder);
        }    else if (p.Opportunity__r.ScheduleRental__c == TRUE) {
                MPM4_BASE__Milestone1_Milestone__c rorder = new MPM4_BASE__Milestone1_Milestone__c();
                rorder.MPM4_BASE__Project__c = p.Id;
                rorder.Name = 'Schedule Rental';
                rorder.MPM4_BASE__Kickoff__c = date.today();
                rorder.OwnerId = '0051a000000STEt';
                miles.add(rorder);
        }    else if (p.Opportunity__r.SendWelcome__c == TRUE) {
                MPM4_BASE__Milestone1_Milestone__c worder = new MPM4_BASE__Milestone1_Milestone__c();
                worder.MPM4_BASE__Project__c = p.Id;
                worder.Name = 'Schedule Welcome';
                worder.MPM4_BASE__Kickoff__c = date.today();
                worder.OwnerId = '0051a000000R80f';
                miles.add(worder);
        }    else (p.Opportunity__r.ScheduleOffsite__c == TRUE) {
                MPM4_BASE__Milestone1_Milestone__c oorder = new MPM4_BASE__Milestone1_Milestone__c();
                oorder.MPM4_BASE__Project__c = p.Id;
                oorder.Name = 'Schedule Offsite';
                oorder.MPM4_BASE__Kickoff__c = date.today();
                oorder.OwnerId = '0051a000000STEt';
                miles.add(oorder);
    }
   }
   
   insert miles;
}