• Nidhi gupta 150
  • 0 Points
  • Member since 2020

  • Chatter
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
  • 2
I'm getting the following error;
"Challenge Not yet complete... here's what's wrong: 
Inserting a new Maintenance Request of type 'Routine Maintenance' and then closing it did not create of a new Maintenance Request based upon the original record correctly. The challenge is expecting to find the closed Maintenance Request plus an 'New' Maintenance Request of type 'Routine Maintenance' with the same Vehicle as the closed one."
I have had a look at the forum links you provided in a previous post but it's not resolving.

I have added 'Routine Maintenance' and 'Repair' in Case field Type. (Why should this be needed and this type is inconsistent with the other picklist types e.g Electrical, Structural etc)
I also include a filed 'Old Case' to store the Case ID once closed. The challenge is to automate through writing the trigger and the helkper class right? No test class is required at this stage?
Here is my code;
trigger MaintenanceRequest on Case (before update, after update) {  
    List<case>ClosedCaseList = [SELECT Id, subject,Reason, Vehicle__c, vehicle__r.Name, equipment__c,type 
                                FROM Case WHERE Id IN :Trigger.New 
                                AND (status = 'closed' AND (type = 'Repair' OR type = 'Routine Maintenance'))];   
    Map<Id, Case>CasesToConsider = new Map<Id, Case>();
    for(Case c: ClosedCaseList){
        Boolean alreadyClosed = Trigger.oldMap.get(c.Id).Status.equals('Closed') ;
            CasesToConsider.put(c.id, c);
    List<Work_Part__c> allWorkParts = [SELECT ID, Equipment__c, Maintenance_Request__c, 
                Quantity__c, Equipment__r.Maintenance_Cycle__c FROM Work_Part__c 
                WHERE Maintenance_Request__c in: CasesToConsider.keySet()];
    MaintenanceRequestHelper.updateWorkOrders(CasesToConsider, allWorkParts);       

public class MaintenanceRequestHelper {
    public static void updateWorkOrders(List<Case> maintenanceRequests){

        Set<Case> targetRequests = new Set<Case>();
        for (Case mr : maintenanceRequests)
            if (('Repair' == mr.Type || 'Routine Maintenance' == mr.Type) && 'Closed' == mr.Status)

        List<AggregateResult> results = [
            SELECT Maintenance_Request__c, MIN(Equipment__r.Maintenance_Cycle__c)
            FROM Work_Part__c
            WHERE Maintenance_Request__c IN :targetRequests
            GROUP BY Maintenance_Request__c

        Map<Id, Integer> requestToMinCycle = new Map<Id, Integer>();
        for (AggregateResult ar : results)

        List<Case> workOrders = new List<Case>();
        for (Case t : targetRequests)
            if (('Repair' == t.Type || 'Routine Maintenance' == t.Type) && 'Closed' == t.Status)
                workOrders.add(new Case(
                    Type='Routine Maintenance',
        if (!workOrders.isEmpty())
            insert workOrders;
Hi all,

I am getting an error that I don't see addressed in the forum.
My tests pass with 100% code coverage when I run the test myself.
My class (from the WSDL) is named "public class ParkService"

Here are the classes I wrote for the challenge:
public class ParkLocator {
    public static string[] country(string theCountry) {
        ParkService.ParksImplPort  parkSvc = new  ParkService.ParksImplPort(); // remove space
        return parkSvc.byCountry(theCountry);
private class ParkLocatorTest {
    @isTest static void testCallout() {              
        Test.setMock(WebServiceMock.class, new ParkServiceMock ());
        String country = 'United States';
        List<String> result = ParkLocator.country(country);
        List<String> parks = new List<String>{'Yellowstone', 'Mackinac National Park', 'Yosemite'};
         System.assertEquals(parks, result); 
global class ParkServiceMock implements WebServiceMock {
   global void doInvoke(
           Object stub,
           Object request,
           Map<String, Object> response,
           String endpoint,
           String soapAction,
           String requestName,
           String responseNS,
           String responseName,
           String responseType) {
        // start - specify the response you want to send
        ParkService.byCountryResponse response_x = new ParkService.byCountryResponse();
        response_x.return_x = new List<String>{'Yellowstone', 'Mackinac National Park', 'Yosemite'};
        // end
        response.put('response_x', response_x); 
Please tell me what I am missing here.