• Dheeraj Sharma
  • NEWBIE
  • 5 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 4
    Replies
I unlocked the apex super badge, but In its very first step, I got stuck. I am not able to complete the very first step. I have created a trigger and helper and I have tested the flow by myself all works well. But still, I am getting below error in trailhead.
User-added image
I have created a trigger on the case.

trigger GenerateMaintenanceCase on Case (before update) {
        ITriggerManager trgrManager = new CaseTriggerHandler();
        TriggerHandler.InvoceHandler(trgrManager);
}

below is the Case trigger handler


public class CaseTriggerHandler implements ITriggerManager{
    
    
    public void onBeforeInsert(List<sObject> newObjLst,Map<Id,sObject> newObjMap){ }
    
    public void onBeforeUpdate(List<sObject> newObj,List<sObject> oldObj,Map<Id,sObject> newMap, Map<Id,sObject> oldMap){
        List<Case> lstOfNewCase = (List<Case>) newObj;
        
        
        List<Case> lstOfCaseToProcess = new List<Case>();
        List<Case> lstOfCaseGetCreated = new List<Case>(); 
        
        for(Case newCase:lstOfNewCase){
            if(''+oldMap.get(newCase.Id).get('Status') != ''+newMap.get(newCase.Id).get('Status') && newMap.get(newCase.Id).get('Status') =='Closed'){
                 lstOfCaseToProcess.add(newCase);
            }
        }
        
        Map<Id,Integer> mapOfLowestWODate = new Map<Id,Integer>();
        if(lstOfCaseToProcess!=null && lstOfCaseToProcess.size()>0 ){
             List<Case> lstOfCase = [SELECT id,Date_Due__c, Vehicle__c,Equipment__c,
                                    (SELECT id,Equipment__r.Maintenance_Cycle__c FROM Work_Parts__r) 
                                     FROM Case 
                                     WHERE Id 
                                     IN :lstOfCaseToProcess];
                                     
             for(Case caseToUpdate: lstOfCase){
                Integer lowest =0;
                for(Work_Part__c workPart: caseToUpdate.Work_Parts__r){
                    if(lowest==0 || lowest>workPart.Equipment__r.Maintenance_Cycle__c){
                       lowest = Integer.valueOf(workPart.Equipment__r.Maintenance_Cycle__c!=null?workPart.Equipment__r.Maintenance_Cycle__c:0);  
                    }
                }
                mapOfLowestWODate.put(caseToUpdate.Id,lowest); 
                Case myCase = new Case();
                //myCase.recordTypeId = mapOfRecordTypeNameToId.get('Routine Maintenance');
                myCase.Type ='Routine Maintenance';
                myCase.subject='As a part of maintenance request';
                myCase.Vehicle__c = caseToUpdate.Vehicle__c;
                myCase.Equipment__c = caseToUpdate.Equipment__c;
                myCase.Date_Reported__c = System.today();
                myCase.Date_Due__c= System.Today()+lowest;
                lstOfCaseGetCreated.add(myCase);
             }
         }
        if(lstOfCaseGetCreated!=null && lstOfCaseGetCreated.size()>0 ){
            insert lstOfCaseGetCreated;
        }
        
    }
    
    public void onAfterInsert(List<sObject> newObj,Map<Id,sObject> newObjMap){}
    
    public void onAfterUpdate(List<sObject> newObj,List<sObject> oldObj,Map<Id,sObject> newMap, Map<Id,sObject> oldMap){}

}

below is the trigger handler

Public class TriggerHandler{

    public static void InvoceHandler(ITriggerManager TriggerMng){
        
        if(Trigger.isBefore){
            
            if(Trigger.isInsert){
                TriggerMng.onBeforeInsert(Trigger.new,Trigger.newMap);
            }
            
            if(Trigger.isUpdate){
               TriggerMng.onBeforeUpdate(Trigger.new,Trigger.old,Trigger.newMap,Trigger.oldMap);                
            }
        }
        if(Trigger.isAfter){
            if(Trigger.isInsert){
                TriggerMng.onAfterInsert(Trigger.new,Trigger.newMap);
            }
            
            if(Trigger.isUpdate){
               TriggerMng.onAfterUpdate(Trigger.new,Trigger.old,Trigger.newMap,Trigger.oldMap);                
            }
        }
    }
}

ITriggerManager  is my interface:

public interface ITriggerManager{
    void onBeforeInsert(List<sObject> newObjLst,Map<Id,sObject> newObjMap);
    void onBeforeUpdate(List<sObject> newObj,List<sObject> oldObj,Map<Id,sObject> newMap, Map<Id,sObject> oldMap);
    void onAfterInsert(List<sObject> newObj,Map<Id,sObject> newObjMap);
    void onAfterUpdate(List<sObject> newObj,List<sObject> oldObj,Map<Id,sObject> newMap, Map<Id,sObject> oldMap);
}


Please help to understand this error and plz let me know if there is an issue with my code.

Thanks,
 
{!pickVal == objRecord.{v.kanbanPicklistField}} is there any workaround to use this type of expression is possible to use in lightning?
I created a lightning component which is a form for editing a related list on an object. I created a lightning action for the component in the object record details page in salesforce. My problem is that the modal the component shows in when the action is clicked has a small width, and the details for each list item become squished/truncated. Is there a solution/alternative for increasing the width of the modal the lighting component appears in?
Hi,

My requirement is to create ApexTrigger in Salesforce dynamically after taking the required inputs from the user.

Is it possible using the SOAP API "create" operation since ApexClass and ApexTrigger are standard objects in Salesforce, 

Regards
Shalindra Singh