You need to sign in to do that
Don't have an account?
Kaylee Gray
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.
This is for the Apex Specialist Challenge 4. All my tests pass and code coverage is 100%.
I'm getting the error when I check the challenge.
In the debug logs they are checking the following " SOQL_EXECUTE_BEGIN [35]|Aggregations:0|SELECT COUNT() FROM Case WHERE Equipment__c = :tmpVar1" which is giving me Assertion Failed: Expected: 402, Actual: 602.
I've read through the log and just can't figure out what's going wrong.
Helper Code:
public class MaintenanceRequestHelper {
public static void updateWorkOrders(List<case>ClosedCaseList){
// update workorders
list<case> insertCaseList = new list<case>();
for(Case c : ClosedCaseList)
{
Case newCase = new Case();
integer days = (integer)c.Equipment__r.Maintenance_Cycle__c;
newCase.Type = 'Routine Maintenance';
newCase.Status = 'New';
newCase.Subject = c.Subject;
newCase.Date_Reported__c = Date.today();
if(days != null){
newCase.Vehicle__c = c.Vehicle__c;
newCase.Date_Due__c = Date.today().addDays(days);
newCase.Equipment__c = c.Equipment__c;
}
insertCaseList.add(newCase);
}
if(insertCaseList.size()>0){
insert insertCaseList;
}
}
}
Trigger:
trigger MaintenanceRequest on Case ( after update) {
List<case>ClosedCaseList = [SELECT Id, Type, Subject, Vehicle__c, Equipment__c, Equipment__r.Maintenance_Cycle__c FROM Case WHERE status = 'Closed'];
List<Case> casesToUpdate = new List<case>();
if(Trigger.isAfter && Trigger.isUpdate){
for(case c : ClosedCaseList){
if(c.type == 'Repair' || c.type =='Routine Maintenance'){
casesToUpdate.add(c);
}
}
}
MaintenanceRequestHelper.updateWorkOrders(casesToUpdate);
}
Thanks in advance for any help.
I'm getting the error when I check the challenge.
In the debug logs they are checking the following " SOQL_EXECUTE_BEGIN [35]|Aggregations:0|SELECT COUNT() FROM Case WHERE Equipment__c = :tmpVar1" which is giving me Assertion Failed: Expected: 402, Actual: 602.
I've read through the log and just can't figure out what's going wrong.
Helper Code:
public class MaintenanceRequestHelper {
public static void updateWorkOrders(List<case>ClosedCaseList){
// update workorders
list<case> insertCaseList = new list<case>();
for(Case c : ClosedCaseList)
{
Case newCase = new Case();
integer days = (integer)c.Equipment__r.Maintenance_Cycle__c;
newCase.Type = 'Routine Maintenance';
newCase.Status = 'New';
newCase.Subject = c.Subject;
newCase.Date_Reported__c = Date.today();
if(days != null){
newCase.Vehicle__c = c.Vehicle__c;
newCase.Date_Due__c = Date.today().addDays(days);
newCase.Equipment__c = c.Equipment__c;
}
insertCaseList.add(newCase);
}
if(insertCaseList.size()>0){
insert insertCaseList;
}
}
}
Trigger:
trigger MaintenanceRequest on Case ( after update) {
List<case>ClosedCaseList = [SELECT Id, Type, Subject, Vehicle__c, Equipment__c, Equipment__r.Maintenance_Cycle__c FROM Case WHERE status = 'Closed'];
List<Case> casesToUpdate = new List<case>();
if(Trigger.isAfter && Trigger.isUpdate){
for(case c : ClosedCaseList){
if(c.type == 'Repair' || c.type =='Routine Maintenance'){
casesToUpdate.add(c);
}
}
}
MaintenanceRequestHelper.updateWorkOrders(casesToUpdate);
}
Thanks in advance for any help.
Please refer below links for a similar issue.
https://developer.salesforce.com/forums/?id=906F0000000kFjcIAE
http://salesforce.stackexchange.com/questions/130242/superbadges-apex-specialist-the-maintenancerequest-trigger-does-not-appear
https://d2hwpln2xvs3s.cloudfront.net/forums/?id=906F0000000kEG5IAM
Hope this helps you!
Please mark it as Best Answer if my reply was helpful. It will make it available for other as the proper solution.
Thanks and Regards
Sandhya
Here's my code for helper class: