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
PseudodarwinistPseudodarwinist 

Error :"Attempt to de-reference a null object, 3332 "

Below is the method which is throwing "Attempt to de-reference a null object, 3332".Can somebody help?
it is called under Before insert and  Update
----------------------------------------------------------------------------------------------------
if(Trigger.isBefore){
        if(Trigger.isInsert)
            R2_CLS_CaseTriggerMethods.checkStatusCountAndDate(news, null);
-------------------------------------------------------------------------------------------------------------------------
if(Trigger.isUpdate)
            R2_CLS_CaseTriggerMethods.checkStatusCountAndDate(news, olds);
------------------------------------------------------------------------------------------------------------------------
public static void checkStatusCountAndDate(List<Case> news, List<Case> olds){
        try{
            if(R1_CLS_LogHelper.isRunningTest()){throw new R1_CLS_LogHelper.R1_Exception('test');} 

            Id rtIdExp = Schema.SObjectType.Case.getRecordTypeInfosByName().get('Expediente').getRecordTypeId();
            Id rtIdCons = Schema.SObjectType.Case.getRecordTypeInfosByName().get('Consulta').getRecordTypeId();
            Id rtIdGDPR = Schema.SObjectType.Case.getRecordTypeInfosByName().get('GDPR').getRecordTypeId();

            //fill the set with the possible status to close a transction
            Set<String> statusEndTransactionSet = new Set<String>();
            statusEndTransactionSet.add('Closed');
            statusEndTransactionSet.add('Cancelled');
            statusEndTransactionSet.add('Waiting on Iberia');
            statusEndTransactionSet.add('Waiting on Cliente');

            for (Integer i = 0; i < news.size(); i++) {
                if (news[i].RecordTypeId == rtIdExp || news[i].RecordTypeId == rtIdCons || news[i].RecordTypeId == rtIdGDPR) {
                    //is insert
                    if (olds == null) {
                        //check if the status corresponding to a close transaction
                        if (statusEndTransactionSet.contains(news[i].Status)) {
                            news[i].R2_CAS_DAT_First_Transaction_date__c = System.Today();
                            news[i].R2_CAS_NUM_Count_Number_Transaction__c = 1;
                        }
                        else if (news[i].Status == 'Reabierto') {
                            news[i].R2_CAS_NUM_Count_Number_Reopen__c = 1;
                            news[i].R2_CAS_DAT_First_Reopen_Date__c = System.Today();
                            news[i].R2_CAS_DAT_Last_Reopen_Date__c = System.Today();
                        }
                    }
                    // is update
                    else {
                        if (!statusEndTransactionSet.contains(olds[i].Status) && statusEndTransactionSet.contains(news[i].Status)) {
                            news[i].R2_CAS_NUM_Count_Number_Transaction__c = olds[i].R2_CAS_NUM_Count_Number_Transaction__c + 1;
                            if (olds[i].R2_CAS_DAT_First_Transaction_date__c == null) {
                                news[i].R2_CAS_DAT_First_Transaction_date__c = System.Today();
                            }
                        }
                        else if (olds[i].Status != news[i].Status && statusEndTransactionSet.contains(olds[i].Status) && news[i].Status == 'Reabierto') {
                            news[i].R2_CAS_NUM_Count_Number_Reopen__c = olds[i].R2_CAS_NUM_Count_Number_Reopen__c + 1;
                            news[i].R2_CAS_DAT_Last_Reopen_Date__c = System.Today();
                            if (olds[i].R2_CAS_DAT_First_Reopen_Date__c == null) {
                                news[i].R2_CAS_DAT_First_Reopen_Date__c = System.Today();
                            }
                            if (olds[i].R2_CAS_DAT_Last_Reopen_Date__c != null) {
                                news[i].R2_CAS_DAT_Penultimate_Reopen_Date__c = olds[i].R2_CAS_DAT_Last_Reopen_Date__c;
                            }
                        }
                    }
                }
            }
        }catch(Exception exc){
            R1_CLS_LogHelper.generateErrorLog('R2_CLS_CaseTriggerMethods.checkStatusCountAndDate()', '', exc.getmessage()+', '+exc.getLineNumber(), 'Case');
        }
    }
Jay Wang 2Jay Wang 2

Hi,

Do the errors tell you which line it is occurring? I personally believe that it could be due to the fact that you are using news and olds in your method call in the trigger. Try replacing them with Trigger.New and Trigger.Old.

Try the below snippet of code.

if(Trigger.isBefore){
        if(Trigger.isInsert)
            R2_CLS_CaseTriggerMethods.checkStatusCountAndDate(Trigger.New, null);
}
if(Trigger.isUpdate)
            R2_CLS_CaseTriggerMethods.checkStatusCountAndDate(Trigger.New, Trigger.Old);
Best of luck,

Jay