+ Start a Discussion
ilewi121ilewi121 

Why do test results differ between Sandbox and Production?

I have tested this trigger multiple times in the Sandbox, and it produces the proper results. However, when I deploy the changes to production, it comes out with different results. Does anyone know how I could trace what is producing the different results in production? I checked workflows and validation rules but couldn't find anything.
Best Answer chosen by ilewi121
ilewi121ilewi121
I found the issue. The trigger was firing twice due to other workflows. The following article gave me what I needed to fix it.

http://raydehler.com/cloud/clod/prevent-an-apex-trigger-from-executing-twice.html

All Answers

ilewi121ilewi121
I should note that the sandbox trigger produces N number of records, but the production trigger produces N+1
ilewi121ilewi121
I found the issue. The trigger was firing twice due to other workflows. The following article gave me what I needed to fix it.

http://raydehler.com/cloud/clod/prevent-an-apex-trigger-from-executing-twice.html
This was selected as the best answer
craveracravera
FYI, I had some code where it worked fine in the Sandbox but not Production.  This code called a future method, and the problem in Production was caused by timing.  In the end, this exposed a flaw in my code so I'm thankful it didn't work in Production because it would certainly have been a fluke.