+ Start a Discussion
Bernie XBernie X 

Code coverage difference betweeen sandbox and production

I have been struggling to understand why code coverage for a trigger is 100% in sandbox and 0% when attempting to deploy to production.
sfdcfoxsfdcfox
There could be a number of reasons, including, but not limited to:

Differences in validation rules.
Differences in required fields.
Not including the appropriate class(es) that provide coverage.
Incorrectly written test methods that rely on hard-coded ID values.
Incorrectly written trigger code that relies on hard-coded ID values.
Compilation errors while trying to deploy the package.
Difference in installed packages that are causing testing failures.

In short, you'll have to check the deployment logs to ascertain why the deployment failed. Setup > Monitoring > Deployments should be able to help you.
Bernie XBernie X
Thanks sfdcfox for your reply.  I have the same validation rules and required fields in my sandbox as my production.  I incluide the test classes. I don't use any hard coded ID values, and I am not deploying a package; just deploying the indivudal triggers and test classes from Force.com IDE.  I have looked at the debug logs.  The triggers that are passing have a certain number of SOQL queries and query rows, under "TESTING_LIMITS" and "LIMIT_USAGE_FOR_NS."  Whereas, the triggers that fail have SOQL queries and query rows both set to 0.

I suppose something is wrong with quering from a test/production point of view.  Now the question is why have a double standard?
Bernie XBernie X
I have Enterprise versions of SFDC, and there is no Setup > Monitoring > Deployments setting.
Bernie XBernie X
Good news!  I solved my own problem (details below) w/ sfdcfox's insight of course.  However, my question and the root of the problem still remains unsolved.  Why does testing/validation differ so greatly between sandbox and production?

Details: My test class gets data from a SOQL query with a limit of 1.  In the developer console query editor, this results in one row; however, in the force.com IDE validation log, the SOQL query generates no rows (SOQL_EXECUTE_END|[8]|Rows:0).  By increasing the limit to 10, I now have 100% code coverage for my trigger.