• Abhishek Malik 9
  • NEWBIE
  • -5 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 2
    Likes Received
  • 2
    Likes Given
  • 2
    Questions
  • 1
    Replies
Hi everyone
am trying to earn apex superbadge but am getting lots of errors like some times my trailhead account does not recognize my developer account and my helper class and trigger does not giving any error but then also my challenge is not completed yet , am sending my code also:
<************HElPER CLASS***************>

public class MaintenanceRequestHelper {

    public static void updateWorkOrders(List<Case> caseList){

        if(caseList.size() > 0){
            List<Case> casesToCreate = new List<Case>();

            List<String> caseIdList = new List<String>();

            for(Case aCase : caseList){
                caseIdList.add(aCase.Id);
            }

            map<String, List<Work_Part__c>> workPartByCase = new map<String, List<Work_Part__c>>();

            for(Work_Part__c aWorkPart : [
                SELECT Id, Name, Equipment__c, Equipment__r.Maintenance_Cycle__c, Maintenance_Request__c
                FROM Work_Part__c
                WHERE Maintenance_Request__c IN :caseIdList
                AND Equipment__c != NULL
            ]){
                if(!workPartByCase.containsKey(aWorkPart.Maintenance_Request__c)){
                    workPartByCase.put(aWorkPart.Maintenance_Request__c, new List<Work_Part__c>()); 
                }

                workPartByCase.get(aWorkPart.Maintenance_Request__c).add(aWorkPart);            
            }

            for(Case aCase : caseList){

                Date dateDue = Date.today();
                Integer minMaintenanceCycle;

                if(workPartByCase.containsKey(aCase.Id)){

                    for(Work_Part__c aWorkPart : workPartByCase.get(aCase.Id)){
                        if(
                            (minMaintenanceCycle == NULL && aWorkPart.Equipment__r.Maintenance_Cycle__c != NULL && aWorkPart.Equipment__r.Maintenance_Cycle__c > 0)
                            || (minMaintenanceCycle != NULL && aWorkPart.Equipment__r.Maintenance_Cycle__c != NULL && aWorkPart.Equipment__r.Maintenance_Cycle__c < minMaintenanceCycle && aWorkPart.Equipment__r.Maintenance_Cycle__c > 0)
                        ){
                            minMaintenanceCycle = Integer.valueOf(aWorkPart.Equipment__r.Maintenance_Cycle__c);
                        }
                    }

                    if(minMaintenanceCycle != NULL){
                        dateDue = dateDue.addDays(minMaintenanceCycle);
                    }
                }

                casesToCreate.add(new Case(
                    Vehicle__c = aCase.Vehicle__c,
                    Equipment__c = aCase.Equipment__c,
                    Type = 'Routine Maintenance',
                    Subject = 'New maintenance request',
                    Date_Reported__c = Date.today(),
                    Date_Due__c = dateDue
                ));
            }

            insert casesToCreate;
        }
    }
}
<************TRIGGER***************>
trigger MaintenanceRequest on Case (before insert, after insert, before update, after update) {

    if(Trigger.isAfter){
        List<Case> caseList = new List<Case>();

        for(Case aCase : Trigger.new){

            if(aCase.IsClosed && aCase.Type != NULL && (aCase.Type.equals('Repair') || aCase.Type.equals('Routine Maintenance'))){
                caseList.add(aCase);
            }
        }

        if(caseList.size() > 0){
            MaintenanceRequestHelper.updateWorkOrders(caseList);
        }
    }
}
 
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.
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.
Performing the first Challenge of this Superbadge for APEX, I am receiving the below error. But it is not true because the Maintenance Request does indeed have all of the attributes cited when I try via the GUI and via a Test Class. Can someone please tell me what is wrong?

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.

(Also, the challenge didn't specifically mention that the Case and Product2 objects should be relabeled)
Am trying to use javascript in a very simple VF page but it is not working can anybody please help me to find out the error.
<----------------PAGE---------------->
<apex:page controller="Example2">

 <script type="text/javascript">
 
    function validate()
    {
        if(document.getElementById('{!$Component.frm.pb.pbs.pbsi1.aa}').value == '')
        {
            alert("FIRST NAME is mandatory");
        }
        if(document.getElementById('{!$Component.frm.pb.pbs.bb}').value == '')
        {
            alert("LAST NAME is mandatory");
        }
         else
        {
            callmove();
            alert("NAME has been inserted CONCATINATED");
        }
    }
        
  </script>  
  <apex:form id="frm"> 
  <apex:actionFunction action="{!move}" name="move" reRender="pb"/>  
   <apex:pageBlock id="pb">   
    <apex:pageBlockSection id="pbs">
               <apex:pageBlockSectionItem ><apex:outputLabel value="FIRST NAME"/></apex:pageBlockSectionItem>
            <apex:pageBlockSectionItem id="pbsi1"><apex:inputText value="{!aa}" id="aa"/></apex:pageBlockSectionItem>
              <apex:pageBlockSectionItem ><apex:outputLabel value="LAST NAME"/></apex:pageBlockSectionItem> 
            <apex:pageBlockSectionItem id="pbsi2"><apex:inputText value="{!bb}" id="bb"/></apex:pageBlockSectionItem>
       <apex:pageBlockSectionItem ><apex:outputLabel value="FULL NAME"/></apex:pageBlockSectionItem> 
            <apex:pageBlockSectionItem id="pbsi3"><apex:inputText value="{!cc}" id="cc"/></apex:pageBlockSectionItem>        
    </apex:pageBlockSection>    
      <apex:pageBlockButtons location="bottom" >      
    <apex:commandButton value="CONCAT" action="{!move}" onclick="move();"/>
        </apex:pageBlockButtons>  
   </apex:pageBlock>
     </apex:form>
 </apex:page>

<----------------CLASS---------------->
public class Example2 {

    public PageReference move() {
    cc=aa+bb;
        return null;
    }

public string aa{get;set;}
public string bb{get;set;}
public string cc{get;set;}
 
public pagereference getMove() {
cc=aa+bb;
return null;
        
    }

}