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
GorhamGuyGorhamGuy 

Please Help! - APEX triggers work perfectly in Full Sandbox but throw an NPE in Production

Hello all,

 

We have a Full Sandbox that we use to develop new APEX code before releasing into production.  This SandBox was recently refreshed and should have identical configuration to our production environment.  After the last time I refreshed, I developed a couple new triggers and bulkified some existing triggers that needed bulkification in the Sandbox.  I tested all of the code changes in the Sandbox and everything worked as expected.  I then pushed them into our production environment where I found that one of the triggers is throwing a Null Point Exception that was not being thrown in the Sandbox.  I performed the exact same steps in the Sandbox as I did in Production when it threw the exception, and everything works fine in the Sandbox.  I compared the field security settings and availability in the objects that the triggers deal with to make sure there wasn't a small chnage that happened in one environment and not the other, but I couldn't see any differences anywhere.  Has anyone seen anything like this before?  Any pointers that anyone could offer would be greatly appreciated.  I am at a loss.  Thanks.

Best Answer chosen by Admin (Salesforce Developers) 
jhurstjhurst

I responded to your case via email.

 

It looks like the issue here is that your triggers are firing in different order on sandbox vs production.  The result is that production hits a section of code that sandbox does not and the error happens.  The same error happens if the triggers fire in the same order.

 

Jay

All Answers

jhurstjhurst

The most common cause is around your triggers being Data Dependent.  For instance, if your trigger looks for a record by ID rather than name and the IDs are different in your sandbox and production.  

 

If you can log a case with all of the details and reproduction steps (and login access granted for your sandbox and prod orgs) and post the case number here, I can take a look and get an answer for you.


Thanks

Jay

GorhamGuyGorhamGuy

Hi Jay, I created a case for this issue.  Case # 04170129.  I granted access to both our production and full sandbox environment and posted the steps needed to reproduce in the case.  I added some test coverage to the TextClass2 APEX class in the Sandbox as well.  The issue can also be reproduced by trying to deploy that class to the production environment.

jhurstjhurst

I responded to your case via email.

 

It looks like the issue here is that your triggers are firing in different order on sandbox vs production.  The result is that production hits a section of code that sandbox does not and the error happens.  The same error happens if the triggers fire in the same order.

 

Jay

This was selected as the best answer
GorhamGuyGorhamGuy

Hi Jay,
 
I appreciate your help.  I combined 3 triggers, where the order of execution was important for the code to function properly, and it is working in both the Sandbox and Production environments. Thank you.

Steve