You need to sign in to do that
Don't have an account?
Sudhir Kumar 19
Apex Superbadge Challenge 4 Error
Challenge Not yet complete... here's what's wrong:
The 'MaintenanceRequest' trigger does not appear to be handling bulk operations correctly. For the positive use case of inserting and updating more than 200 records, it did not produce the expected outcome.
When I debug, I see this strange SOQL:
11:07:41.744 (4865812076)|SOQL_EXECUTE_BEGIN|[35]|Aggregations:0|SELECT COUNT() FROM Case WHERE subject LIKE '%AMC Spirit%'
11:07:41.744 (4868187164)|SOQL_EXECUTE_END|[35]|Rows:201
11:07:41.744 (4868199387)|HEAP_ALLOCATE|[35]|Bytes:4
11:07:41.744 (4868273203)|EXCEPTION_THROWN|[35]|System.AssertException: Assertion Failed: Expected: 402, Actual: 201
11:07:41.744 (4868404432)|HEAP_ALLOCATE|[35]|Bytes:48
11:07:41.744 (4868515907)|FATAL_ERROR|System.AssertException: Assertion Failed: Expected: 402, Actual: 201
I see many people passing this challenge. Kindly help!
Apex Superbadge Challenge 4 Error: The 'MaintenanceRequest' trigger does not appear to be handling bulk operations correctly.
Apex Superbadge Challenge 4 Error
Challenge Not yet complete... here's what's wrong:
The 'MaintenanceRequest' trigger does not appear to be handling bulk operations correctly. For the positive use case of inserting and updating more than 200 records, it did not produce the expected outcome.
When I debug, I see this strange SOQL:
11:07:41.744 (4865812076)|SOQL_EXECUTE_BEGIN|[35]|Aggregations:0|SELECT COUNT() FROM Case WHERE subject LIKE '%AMC Spirit%'
11:07:41.744 (4868187164)|SOQL_EXECUTE_END|[35]|Rows:201
11:07:41.744 (4868199387)|HEAP_ALLOCATE|[35]|Bytes:4
11:07:41.744 (4868273203)|EXCEPTION_THROWN|[35]|System.AssertException: Assertion Failed: Expected: 402, Actual: 201
11:07:41.744 (4868404432)|HEAP_ALLOCATE|[35]|Bytes:48
11:07:41.744 (4868515907)|FATAL_ERROR|System.AssertException: Assertion Failed: Expected: 402, Actual: 201
I see many people passing this challenge. Kindly help!
Please this link it might help you out.
http://salesforce.stackexchange.com/questions/130242/superbadges-apex-specialist-the-maintenancerequest-trigger-does-not-appear
Thanks
Paarth Jolly
This doens't seem working. No clues how to assert trailhead validation.
" When an existing maintenance request of type Repair or Routine Maintenance is Closed, you create a new maintenance request for a future routine checkup. This new request is tied to the same vehicle and piece of equipment to be serviced as the original closed service request. This new request's Type should be set as Routine Maintenance. The Subject should not be null and the Report Date field reflects the day the request was created. Another aspect about parts is they all have different lifespans. Therefore, you need to calculate and set the next due date using the maintenance cycle defined on the related work part records. If multiple work parts are used in the maintenance request, choose the shortest maintenance cycle to define the service date."
When I reviewed the log, I noticed that the challenge test code is querying for all Case records that have a similar Subject value to verify that new Case records are created:
SELECT COUNT() FROM Case WHERE subject LIKE '%AMC Spirit%'
After seeing this, I set the Subject of the new Case records = to the Subject of the Case that is being closed and was able to complete the 4th challenge.
Hope that helps.
You have to insert as many work parts records for each inserted new case record.
Here is my code for helper class:
public with sharing class MaintenanceRequestHelper {
public static void updateWorkOrders(List<Case> caseList) {
List<case> newCases = new List<Case>();
Map<String,Integer> result=getDueDate(caseList);
list<Equipment_Maintenance_Item__c> itemsListToinsert= new list<Equipment_Maintenance_Item__c>();
Map<String,list<Equipment_Maintenance_Item__c>> resultItmes=getMaintainanceItems(caseList);
for(Case c : caseList){
if(c.status=='closed')
if(c.type=='Repair' || c.type=='Routine Maintenance'){
Case newCase = new Case();
newCase.Status='New';
newCase.Origin='web';
newCase.Type='Routine Maintenance';
newCase.Subject='Routine Maintenance of Vehicle';
newCase.Vehicle__c=c.Vehicle__c;
newCase.Equipment1__c=c.Equipment1__c;
newCase.Date_Reported__c=Date.today();
newcase.Cloned_Case_Id__c=c.Id;
if(result.get(c.Id)!=null)
newCase.Date_Due__c=Date.today()+result.get(c.Id);
else
newCase.Date_Due__c=Date.today();
newCases.add(newCase);
}
}
if(newCases.size()>0)
{
insert newCases;
for(Case c : newCases){
List<Equipment_Maintenance_Item__c> temp = resultItmes.get(c.Cloned_Case_Id__c);
if(temp !=null){
for(Equipment_Maintenance_Item__c row:temp){
Equipment_Maintenance_Item__c newitem = new Equipment_Maintenance_Item__c();
newitem.Equipment__c=row.Equipment__c;
newitem.Maintenance_Request__c= c.Id;
newitem.Quantity__c= row.Quantity__c;
itemsListToinsert.add(newitem);
}
}
}
}
if(itemsListToinsert.size()>0)
insert itemsListToinsert;
}
//
public static Map<String,Integer> getDueDate(List<case> CaseIDs){
Map<String,Integer> result = new Map<String,Integer>();
Map<Id, case> caseKeys = new Map<Id, case> (CaseIDs);
List<AggregateResult> wpc=[select Maintenance_Request__r.ID cID,min(Equipment__r.Maintenance_Cycle__c)cycle
from Equipment_Maintenance_Item__c where Maintenance_Request__r.ID in :caseKeys.keySet() and Equipment__r.Maintenance_Cycle__c != null group by Maintenance_Request__r.ID ];
for(AggregateResult res :wpc){
Integer addDays=0;
if(res.get('cycle')!=null)
addDays+=Integer.valueOf(res.get('cycle'));
result.put((String)res.get('cID'),addDays);
}
return result;
}
public static Map<String,list<Equipment_Maintenance_Item__c>> getMaintainanceItems(List<case> CaseIDs){
Map<String,list<Equipment_Maintenance_Item__c>> mapofMaintainanceItems = new Map<String,list<Equipment_Maintenance_Item__c>>();
Map<Id, case> caseKeys = new Map<Id, case> (CaseIDs);
list<Equipment_Maintenance_Item__c> lstrec = new list<Equipment_Maintenance_Item__c>([select id ,Maintenance_Request__c,Equipment__c,Quantity__c
from Equipment_Maintenance_Item__c where Maintenance_Request__r.ID in :caseKeys.keySet() ]);
for(Equipment_Maintenance_Item__c row:lstrec){
if (mapofMaintainanceItems.containsKey(row.Maintenance_Request__c)) {
List<Equipment_Maintenance_Item__c> temp = mapofMaintainanceItems.get(row.Maintenance_Request__c);
temp.add(row);
mapofMaintainanceItems.put(row.Maintenance_Request__c, temp);
}
else{
mapofMaintainanceItems.put(row.Maintenance_Request__c, new List<Equipment_Maintenance_Item__c> { row });
}
}
return mapofMaintainanceItems;
}
}