I have added a new method in a class and added test data in the test class . It was PASS when I Ran the test class in Sandbox.

However , when I'm trying to deploy in Prod through Change Set, It's giving me "Null pointer Exception " error .

System.NullPointerException: Attempt to de-reference a null object Stack Trace: Class.MyClass.MyNewMethod: line 516, column 1 Class.MyClassTest.MyTestMethod: line 73, column 1

MyNewMethod is the same method which I have written newly and trying to deploy.

Please suggest why such error.

  • 2
    If you don't share any code it will be hard for us to know why the code threw a null pointer exception – Mihai Neagoe Apr 20 '15 at 10:31
  • 1
    Please share your code. You need to put null checks through out the class. – Nilesh Mane Apr 20 '15 at 11:05

Best guess is that you have a hard-coded ID in your test from the sandbox that will be different or non-existent in production.

You will need to remove all hard-coded IDs from the tests and make them org independant by setting up the required test data within the test.

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.