• suneel sunkara
  • NEWBIE
  • 5 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 2
    Replies
Challenge Not yet complete... here's what's wrong: 
There was an unexpected error in your org which is preventing this assessment check from completing: System.DmlException: Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Validation Formula "RecurringChargeTypeMustHaveBillingType" Invalid (Field 00N6F00000HyvBc is inaccessible. Please review all fields referenced by the formula. Context: common.config.entity.ValidationFormulaContext): []...............
can someone help me get around this in the Apex Specialist Super Badge?
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,