You need to sign in to do that
Don't have an account?
uday uday chavan
salesforce superbadge challenge 1
i am getting this errot
Challenge Not yet complete... here's what's wrong:
Closing a Maintenance Request of type 'Routine Maintenance' or 'Repair' did not create of a new Maintenance Request with the correct due date. The challenge is expecting the due date to be calculated using the maintenance cycle defined on the related equipment records. If multiple equipments are used in the maintenance request, choose the shortest maintenance cycle to define the service date.
Close errors
Trigger handler
public with sharing class MaintenanceRequestHelper {
public static void updateWorkOrders(list<Case> Cases) {
Map<Id,Case> caseLst = new Map<Id,Case>();
for(Case c:Cases){
if (c.IsClosed && (c.Type.equals('Repair') || c.Type.equals('Routine Maintenance'))){
caseLst.put(c.Id,c);
}
}
Map<Id, Integer> mapProduct = new Map<Id, Integer>();
List<Case> CaseList = new List<Case>();
List<Product2> listProduct = [select Id, Maintenance_Cycle__c from Product2];
for (Product2 p : listProduct) {
if (p != null) {
if(p.Maintenance_Cycle__c != null){
mapProduct.put(p.Id, Integer.valueOf(p.Maintenance_Cycle__c));
}
}
}
for(Case a: caseLst.values()){
Case newCase = new Case();
newCase.Vehicle__c = a.Vehicle__c;
newCase.Equipment__c = a.Equipment__c;
newCase.Type = 'Routine Maintenance';
newCase.Subject = String.isBlank(a.Subject) ? 'Routine Maintenance Request' : a.Subject;
newCase.Date_Reported__c = Date.today();
newCase.Status = 'New';
newCase.Product__c = a.Product__c;
newCase.AccountId = a.AccountId;
newCase.ContactId = a.ContactId;
newCase.AssetId = a.AssetId;
newCase.Origin = a.Origin;
newCase.Reason = a.Reason;
newCase.Date_Due__c = (mapProduct.get(a.Id) != null) ? (Date.today().addDays(Integer.valueOf(mapProduct.get(a.Id)))) : (Date.today());
CaseList.add(newCase);
}
if(CaseList.size() > 0){
insert CaseList;
}
}
}
Trigger
trigger MaintenanceRequest on Case (before update, after update) {
if(Trigger.isUpdate && Trigger.isAfter){
MaintenanceRequestHelper.updateWorkOrders(Trigger.new);
}
}
Challenge Not yet complete... here's what's wrong:
Closing a Maintenance Request of type 'Routine Maintenance' or 'Repair' did not create of a new Maintenance Request with the correct due date. The challenge is expecting the due date to be calculated using the maintenance cycle defined on the related equipment records. If multiple equipments are used in the maintenance request, choose the shortest maintenance cycle to define the service date.
Close errors
Trigger handler
public with sharing class MaintenanceRequestHelper {
public static void updateWorkOrders(list<Case> Cases) {
Map<Id,Case> caseLst = new Map<Id,Case>();
for(Case c:Cases){
if (c.IsClosed && (c.Type.equals('Repair') || c.Type.equals('Routine Maintenance'))){
caseLst.put(c.Id,c);
}
}
Map<Id, Integer> mapProduct = new Map<Id, Integer>();
List<Case> CaseList = new List<Case>();
List<Product2> listProduct = [select Id, Maintenance_Cycle__c from Product2];
for (Product2 p : listProduct) {
if (p != null) {
if(p.Maintenance_Cycle__c != null){
mapProduct.put(p.Id, Integer.valueOf(p.Maintenance_Cycle__c));
}
}
}
for(Case a: caseLst.values()){
Case newCase = new Case();
newCase.Vehicle__c = a.Vehicle__c;
newCase.Equipment__c = a.Equipment__c;
newCase.Type = 'Routine Maintenance';
newCase.Subject = String.isBlank(a.Subject) ? 'Routine Maintenance Request' : a.Subject;
newCase.Date_Reported__c = Date.today();
newCase.Status = 'New';
newCase.Product__c = a.Product__c;
newCase.AccountId = a.AccountId;
newCase.ContactId = a.ContactId;
newCase.AssetId = a.AssetId;
newCase.Origin = a.Origin;
newCase.Reason = a.Reason;
newCase.Date_Due__c = (mapProduct.get(a.Id) != null) ? (Date.today().addDays(Integer.valueOf(mapProduct.get(a.Id)))) : (Date.today());
CaseList.add(newCase);
}
if(CaseList.size() > 0){
insert CaseList;
}
}
}
Trigger
trigger MaintenanceRequest on Case (before update, after update) {
if(Trigger.isUpdate && Trigger.isAfter){
MaintenanceRequestHelper.updateWorkOrders(Trigger.new);
}
}
Trailhead Help (https://trailhead.salesforce.com/en/help?support=home)can provide assistance for situations where Trailhead does not appear to be functioning correctly. You can reach out to them if this is the case.
Please close the thread by selected as Best Answer so that we can keep our community clean
Thanks,