function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Vineet Anand 5Vineet Anand 5 

Apex Specialist - Challenge 1.

Hi All,
For Apex Specialist-Challange 1, I am facing below error.

"Challenge Not yet complete... here's what's wrong:
Inserting a new Maintenance Request of type 'Routine Maintenance' and then closing it did not create of a new Maintenance Request based upon the original record correctly. The challenge is expecting to find the closed Maintenance Request plus an 'New' Maintenance Request of type 'Routine Maintenance' with the same Vehicle as the closed one."

Below is my Code:
trigger MaintenanceRequest on Case (before update,after update) 
{
    if (TriggerHelperClass.MyBool==TRUE) 
        {
           MaintenanceRequestHelper.updateWorkOrders();
           TriggerHelperClass.MyBool=FALSE;
        }       
}

wMaintenanceRequestList= new List<Case>();
   for(Case cas:maintenanceRequestList){
     if(cas.Type=='Routine Maintenance' &&  cas.Status=='Closed'){
       case newMaintenanceRequest=new Case();
       newMaintenanceRequest.Subject='test';
       newMaintenanceRequest.Type='Routine Maintenance';
       newMaintenanceRequest.Vehicle__c= cas.Vehicle__c;
       newMaintenanceRequest.Equipment__c = cas.Equipment__c;
       newMaintenanceRequest.Date_Reported__c =date.Today();
       newMaintenanceRequest.Date_Due__c=Date.today().addDays(Integer.valueOf(cas.Equipment__r.Maintenance_Cycle__c));
       newMaintenanceRequest.Status='New';
       newMaintenanceRequest.Origin='Phone';
       newMaintenanceRequestList.add(newMaintenanceRequest);
     }
   }
       return newMaintenanceRequestList;
  }
}

public class TriggerHelperClass
{
    Public static boolean MyBool=TRUE;
}

When Boolean Variable was not Introduced, Code was going in Loop, to avoid loop added Boolean variable. Please suggest reason of error & if possible sol. for same.

Rgd's
Vineet Anand
Jessica RiffeJessica Riffe
What are you passing to your method?  It appears as though you are not passing any trigger new or trigger old variables to loop through.  You want to create your new record in the after update context as well, not run it in both before and after actions of the trigger.
 
MaintenanceRequestHelper.updateWorkOrders();