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
Rahul Rawat 21Rahul Rawat 21 

Apex Specialist Challenge 1 : Closing a Maintenance Request of type 'Routine Maintenance' or 'Repair' did not join the new Maintenance Request with the correct equipment.

Hi All
 I am facing this error from trailhead 
Challenge Not yet complete... here's what's wrong:
Closing a Maintenance Request of type 'Routine Maintenance' or 'Repair' did not join the new Maintenance Request with the correct equipment. The challenge is expecting the new Maintenance Request to be joined to the same Equipment as the closed Maintenance Request.

My Code 
For Trigger -> 


trigger Create_New_Maintenance_Request on Case (after insert,after update) {
    Create_Maintenance_Request_HelperClass.Create_Request(trigger.new);
}


For Helper Class ->

public class Create_Maintenance_Request_HelperClass {
    public static void Create_Request(list<case> request)
    {
        list<case> caseList=new list<case>();
        map<id,aggregateResult> cycle=new map<id,aggregateResult>([select maintenance_request__c Id,min(equipment__r.maintenance_cycle__c) days from Equipment_Maintenance_Item__c where maintenance_request__c!=null group by maintenance_request__c]);
        for(case c:request)
        {
            if(c.status=='Closed' && (c.Type=='Repair'||c.Type=='Routine Maintenance'))
            {
                //Creating a new Maintenance Request/Case record
                case ca=new case();
                ca.Subject='Created after closing of '+c.Id;
                ca.origin='Phone';
                ca.status='New';
                ca.Type='Routine Maintenance';
                ca.vehicle__c=c.vehicle__c;
                ca.equipment__c=c.Equipment__c;
                system.debug('Vehicle id is ->'+c.Vehicle__r.id);
                ca.date_reported__c=date.newInstance(System.now().year(),System.now().month(),System.now().day());
                
                if(cycle.get(c.id)!=null)
                {system.debug('Actual value is -> '+cycle.get(c.id).get('days'));

                ca.Date_Due__c=ca.date_reported__c.addDays(Integer.valueof(cycle.get(c.id).get('days')));
                }caseList.add(ca);
  
            }
            
        }
        insert caseList;
        
    }

}


//I  don't know why i am getting this error despite i myself tested the code
AbhinavAbhinav (Salesforce Developers) 
Hi Rahul,


Please note that Questions about how to pass Trailhead challenges are not on topic, because these challenges are intended to be independent demonstrations of your abilities.Trailhead Help (https://trailhead.salesforce.com/en/help?support=home)can provide assistance for situations where Trailhead does not appear to be functioning correctly. You can reach out to them if this is the case.

Thanks!
 
Rahul Rawat 21Rahul Rawat 21
Thanks for guidance.
Akshay Phadnis 8Akshay Phadnis 8

From where did you change the API name of Lookup to Equipment field on Cases to Equipment__c? I am not getting option to edit that.

ANd I am also facing same error despite of functionality working properly.