You need to sign in to do that
Don't have an account?
Rameshwar gaur
apex specialist badge
i get that error on automated record creation
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.
This is trigger code
And trigger helper class
Thank You
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.
This is trigger code
trigger MaintenanceRequest on Case (before update, after update) { // call MaintenanceRequestHelper.updateWorkOrders if(Trigger.isUpdate) { MaintenanceRequestHelper.updateWorkOrders(trigger.new , trigger.oldmap); } }
And trigger helper class
public class MaintenanceRequestHelper { public static void updateWorkOrders(list<case> triggerlist,map<id,case> triggermap){ // update workorders list<case> FutureMaintenanceList = new list<case>(); list<product2> prdlst = new list<product2>(); try { prdlst =new list<product2>([SELECT Cost__c,Id,IsActive,Lifespan_Months__c,Maintenance_Cycle__c,Name,ProductCode,Replacement_Part__c FROM Product2]); } catch(exception e) { System.debug('Error Caught !!! '+e.getMessage()); } map<id,product2> equipment = new map<id,product2>(prdlst); for(case cs:triggerlist) { if(triggermap.get(cs.id).status != 'closed' && cs.Status == 'closed') { case NewMaintenance = new case(); date Todaydate = date.today(); NewMaintenance.AccountId = cs.AccountId; NewMaintenance.ContactId = cs.ContactId; NewMaintenance.AssetId = cs.AssetId; NewMaintenance.Subject ='Vehicle '+cs.Vehicle__c+' future Maintenance '; NewMaintenance.Vehicle__c=cs.Vehicle__c; NewMaintenance.Date_Reported__c= Todaydate ; NewMaintenance.Equipment__c = cs.Equipment__c; NewMaintenance.Type = 'Routine Maintenance'; NewMaintenance.Status = 'New'; NewMaintenance.Origin =cs.Origin; NewMaintenance.Date_Due__c=Todaydate.adddays(integer.valueOf(math.round(equipment.get(cs.Equipment__c).Maintenance_Cycle__c))); FutureMaintenanceList.add(NewMaintenance); integer x =integer.valueOf(math.round(equipment.get(cs.Equipment__c).Maintenance_Cycle__c)); system.debug('value--'+x); } } system.debug('FutureMaintenanceList--'+FutureMaintenanceList); if(FutureMaintenanceList.size() >0) { insert FutureMaintenanceList; } } }Can any one tell me what i doing wrong.
Thank You
Raj Vakati
Use this code
Rameshwar gaur
Still got the same error.