+ Start a Discussion

unable to deploy trigger in production

I have written an apex trigger in Sandbox. It is working fine. I have written apex class to test the trigger and when i run the tests, it is showing 94% coverage.
But when i try to deploy it into production using eclipse force.com ide and validate deployment, it throws an error saying
Test coverage of selected Apex Trigger is 0%, at least 1% test coverage is required
I have gone through dev community and tried many options like changing api version to 11.0 in xml files but it was of no use.

Please suggest me a solution for this asap.


Salaamz Iqbal,

I suggest you try the ant deployment tool - it makes things a lot more easier.  And with your nick being "j2ee", it shouldn't really be a problem for you, would it? :smileyhappy:

I personally haven't had any luck with Force.com IDE in this regard.  Trust me, I've wasted quite a few billable hours over this! :smileymad:  The Force.com IDE is a good tool, but I think there's a lot that still needs to be done, and this issue is one of them.  That said, do post here if you get to resolve this issue.


Wassalam soof,
thanks .. i tried doing it in ant ..
but am facing same error.
How to increase the test coverage? any ideas

Ok, a few basic guidlines:
  • Make sure that all the data that you use in your test methods is created right there.  Don't use existing data from the system.  I'm guessing that this might be a cause of tests working in sandbox, but failing in production.  If you have specified some ID's of data in sandbox, they're most likely not going to be available in Production, and will cause the tests to fail.
  • Think through and try to use as diverse data set as possible, so that all scenarios in your code are covered.
  • Use a lot of assert statements.  This way, the deployment tool will tell you which assert fails, which will give you some direction.
  • When you're completely lost about where the control is going in your business logic (when invoked from a test method) and where it's not going, use a DESI elimination method that I use.  In your business logic, which is being invoked from the test method, insert assert statements that will always fail.  For instance, in different places in your code, put this statement:

    Now, when you try deploying the code, it will fail on the first "System.assert(false);" statement that it hits, and will indicate the line number.  This will give you an idea of where the control is going, and where it's not.  Then you can investigate why the control is not going to a certain block, which is causing the code coverage %age to fall.

Hope this helps!


Remember also to have the same validation rules enabled in your sandbox as your live system.  I had this same issue but forgot I hadn't bothered to create a validation rule in Sandbox. 



.Creating the test data in the test methods is most important. dont use the existing data(like hard coding (or) retrieving the data using the select queries) in the test methods. that might be the cause for the failure.

. The other point might be, since you might not have covered the events on which your trigger is being called. say if you trigger gets invoked on insert event, your test method should have an insert call so that it covers the trigger in the test method.