2

I am getting NULL POINT Exception error when running my unit tests and can't seem to figure out how to go about this one.

This is the error Message;

|FATAL_ERROR|System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, AccountHttpCallout: execution of AfterInsert

caused by: System.NullPointerException: Attempt to de-reference a null object

It seems the error is being caused by this line

Account oldAcc = Trigger.oldMap.get(a.Id);

 trigger AccountHttpCallout on Account (after insert, after update) {

    //URL should be {CommandType}/{SalesforceId}/{LastModifiedUser}
if(!CallFutureCallOnce.b){
    CallFutureCallOnce.recursiveHelper(true);   

    for (Account a : Trigger.new) {
        Account oldAcc = Trigger.oldMap.get(a.Id);
            String SalesforceId = a.id;
            String LastModifiedUser = a.LastModifiedById;
     if(a.LastModifiedbyId != '00540000001uezb')
        if (trigger.new.size()>1){

            return;

            }
            else{


                       //Send Call on Account Team Update
             system.debug('oldAcc======>>'+oldAcc);        
              if(oldAcc != null && Trigger.isUpdate ){         
                if(a.RecordTypeID == Utilities.ProspectAccount && a.Type == 'Client'){   

                     if( a.Client_Services_Director__c != oldAcc.Client_Services_Director__c ||
                            a.ASM__c != oldAcc.ASM__c ||
                            a.Onboarding_Manager__c != oldAcc.Onboarding_Manager__c ||
                            a.Compliance_Manager__c != oldAcc.Compliance_Manager__c ||
                            a.Owner != oldAcc.Owner ) {             


                        String DMLAction = 'UpdateAccountTeam';
                        HttpCallOutGlobalClass.sendNotification(DMLAction, SalesforceId, LastModifiedUser);
                            }
                }

                    //Send Call on all other updates
                if(a.RecordTypeID == Utilities.ProspectAccount && a.Type == 'Client'){   
                    if( a.Client_Services_Director__c == oldAcc.Client_Services_Director__c ||
                            a.ASM__c == oldAcc.ASM__c ||
                            a.Onboarding_Manager__c == oldAcc.Onboarding_Manager__c ||
                            a.Compliance_Manager__c == oldAcc.Compliance_Manager__c ||
                            a.Owner == oldAcc.Owner )  {

                        String DMLAction = 'SalesforceAccountModified';
                        HttpCallOutGlobalClass.sendNotification(DMLAction, SalesforceId, LastModifiedUser);
                            }

                }

              }
           }
        }
    }

}
2

You may be getting this error because of the trigger events you are using. There is nothing old to compare against when you are inserting data. oldmap is relevant only in update and delete scenario.

(after insert, after update)

Trigger.oldmap is relevant only for update and delete triggers. As per documentation :

https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_triggers_context_variables.htm

oldMap : A map of IDs to the old versions of the sObject records. Note that this map is only available in update and delete triggers.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.