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
zspacekcczspacekcc 

Null pointer exception in trigger before code execution begins.

I'm getting a strange error when trying to run some unit tests. I know the trigger works fine when used outside the unit tests. When running the unit tests, I create some sample data, and when I try to insert it, I get this exception:

System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, <trigger name>: execution of AfterInsert caused by: System.NullPointerException: Argument 1 cannot be null External entry point: []

 

I've looked on here, and I know string.valueOf() can throw this if the value is null, but it's not even reaching my code before it throws this, and I'm not using any valueOf() calls in the triger. It's not giving me an line number in the trigger that's causing the problem. Can any give me an idea of why this is happening? This unit test has been stable for months, and now all of the sudden it's failing.

 

I have no custom validation on this object.

Damien_Damien_

It's useful to show what line of code fails and then the point up to which it fails so that we can better see what's happening.

VKrishVKrish

One possibility of this error is when there is a method invocation involved. Either the method returns a null value in certain case which is not received appropriately in the other end. Or you are passing the value of method's argument as null in certain case.

Use system.debug() in your code and check the debug logs to find the exact location where the system throws error.

Another possibility is that you are missing the value of a mandatory field while inserting. I think its the 2nd case.