function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Mark Z DeanMark Z Dean 

Apex Specialist - Step 4 Failing with Bulkificatioon

Folks - I really need some help. I have run out of brain power solving this for 2 days and can't figure out what's happening. Test class passes with 100% coverage but challenge fails with message:
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.

Here is my main helper class which is called from the trigger:
public class MaintenanceRequestHelper {
    
    public static void processRequest(Map<Id, Case> OldMap, Map<Id, Case> NewMap){
        
       // Id PartsListId;
        Map<Id, Case> MinMaintDaysMap = NewMap;
        Map<Id, Integer> DaystoAdd;
        List<Case> ListofCases = new List<Case>();

   		DaystoAdd = minMaintenanceDays(NewMap);


		for(Id o : NewMap.keySet()){
			if((NewMap.get(o).Type == 'Repair' || NewMap.get(o).Type == 'Routine Maintenance') && NewMap.get(o).status == 'Closed'){
				for(Id i : DaystoAdd.keyset()){		
					if(NewMap.get(o).id == i){
				Case newCase = new Case(Vehicle__c = NewMap.get(o).Vehicle__c,
										Subject = NewMap.get(o).subject,
										Equipment__c = NewMap.get(o).Equipment__c,
										Date_Reported__c = 	System.today(),
										Type = 'Routine Maintenance',
										Status = 'New',
										Origin = 'Web',
										Date_Due__c =System.today() + DaystoAdd.get(i),
										Account = NewMap.get(o).account,
										ContactId = NewMap.get(o).contactId);
				ListofCases.add(newCase);

											}		
									}
							}	
					}
	insert ListofCases;
}        
    


    public static Map<Id, Integer> minMaintenanceDays(Map<Id, Case> Parts){

    	List<Decimal> ListofDays 	= new List<Decimal>();
    	Map<Id, Integer> SortedMap 	= new Map<Id, Integer>();

    	Map<Id, Case> PartsList = new Map<Id, Case>([select id, 
    												(select id, Maintenance_Request__c, Equipment__r.Maintenance_Cycle__c  
    												from Work_Parts__r)
													from Case 
													where id IN :Parts.keyset()]);

		for(Case c  : PartsList.values())			
			for(Work_Part__c wp : c.Work_Parts__r){
				if(c.id == wp.Maintenance_Request__c){				
				//System.debug(wp);
				ListofDays.add(wp.Equipment__r.Maintenance_Cycle__c);
				ListofDays.sort();
				SortedMap.put(c.id, (Integer)ListofDays.get(0));
				}
					}


	return SortedMap;				
    }

}

Please forgive the bad naming conventions and help with the message. Done Googling, StackExchange etc. but for the life of me can't figure out what's wrong. Also Debug log shows the message that assertion fails when challenge is run. Message is "Assestion Failed, Expected: 402, Actual: 201".