You need to sign in to do that
Don't have an account?
![Vineet Anand 5 Vineet Anand 5](https://dfc-org-production.my.site.com/img/userprofile/default_profile_45_v2.png)
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
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 Riffe Jessica Riffe](https://dfc-org-production.my.site.com/img/userprofile/default_profile_45_v2.png)
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.