You need to sign in to do that
Don't have an account?
Maurissa Thomas
Apex Specialist Challenge 4 Help
Hello all,
I am currently trying to finish my Apex Specilaist Superbadge, I am stuck on Challenge 4 which is testing automation logic. I keep recieving this error and i'm not sure where I am wrong:
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.
I will post my test code along with my helper class in the comments. I have tested for up to 300 records so I'm not sure what the problem is. Any help or points in the right direction would be greatly appreciated.
Thank you!
I am currently trying to finish my Apex Specilaist Superbadge, I am stuck on Challenge 4 which is testing automation logic. I keep recieving this error and i'm not sure where I am wrong:
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.
I will post my test code along with my helper class in the comments. I have tested for up to 300 records so I'm not sure what the problem is. Any help or points in the right direction would be greatly appreciated.
Thank you!
public class MaintenanceRequestHelper {
public static void updateWorkOrders() {
// TODO: Complete the method to update workorders
List<Case> caseList =[
SELECT id, Equipment__c, status, type, subject, vehicle__c, Equipment__r.Maintenance_Cycle__c
FROM Case
Where Status = 'Closed' AND Type IN ('Repair','Routine Maintenance')];
List<Case> newCases = new List<Case>();
for (Case c: caseList){
Case nc = new Case();
nc.Type = 'Routine Maintenance';
nc.subject = 'New';
nc.Vehicle__c = c.Vehicle__c;
nc.Equipment__c = c.Equipment__c;
nc.Date_Reported__c = date.today();
if (c.Equipment__r.Maintenance_Cycle__c != null){
nc.Date_Due__c = date.today().addDays(Integer.valueOf(c.Equipment__r.Maintenance_Cycle__c));}
newCases.add(nc);
}
insert newCases;
}
}
@isTest
public class MaintenanceRequestHelperTest {
@isTest static void testMaintenanceRequest(){
List<Case> maintenanceList=new List<Case>();
List<Case> secondMaintenanceList=new List<Case>();
Vehicle__c vehicle=new Vehicle__c(Name='test vehicle',Air_Conditioner__c=true,Model__c='Test');
insert vehicle;
Product2 equipment=new Product2(Name='test tire',Cost__c=100,Current_Inventory__c =10,Replacement_Part__c=true,
Warehouse_SKU__c ='test',Lifespan_Months__c =10,Maintenance_Cycle__c=10);
insert equipment;
for(Integer i=1;i<300;i++){
Case maintenance=new Case(Subject='Test subject'+i,Type='Routine Maintenance'+i,Status='New'+i,
Origin='Phone'+i,Equipment__c=equipment.Id,Vehicle__c=vehicle.Id);
maintenanceList.add(maintenance);
}
insert maintenanceList;
system.assertEquals(300, maintenanceList.size());
for(Case caseupdate:maintenanceList){
caseupdate.Status='Closed';
caseupdate.Type='Routine Maintenance';
caseupdate.Date_Due__c=date.Today().addDays(Integer.valueOf(equipment.Maintenance_Cycle__c));
secondMaintenanceList.add(caseupdate);
}
Test.startTest();
Database.SaveResult[] updatequipment = Database.update(secondMaintenanceList);
Test.stopTest();
for(Database.SaveResult sa:updatequipment){
System.assert(sa.isSuccess());}
}
}
We have separate Trailhead team who can help you with these issues. So, can you please use the below link to reach out to them so that one of the Engineers will get in touch with you.
Support: https://trailhead.salesforce.com/en/help?support=home
Please mark this answer as best if it helps so that others facing same issue will find it useful.
Thanks