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
Lars CadeLars Cade 

Insufficient Code Coverage

I am taking my first timid steps into Apex development and have run up against a problem. Even though all the apex classes being used so far are managed or from the SalesForce App Exchange, I get an error saying I have 23% code coverage when trying to deploy. How can I determine where the fault may lie or run something to improve the situation?
GauravGargGauravGarg
Hi Lars,

Please use developer console to find out the actuall code coverage of all the classes in your org. 

Please contact me in-case you need help on this. 

Thanks,
Gaurav
Email: gauravgarg.nmims@gmail.com
Skype: gaurav62990
Vishal ShelarVishal Shelar
Hey Lars,

There might be some classes which might not be covered completely or atleast 75% (Requirement for deploying to the production).
If you run the all the test classes to test the custom apex classes in developer console you can check that in "Tests" tab and on the right hand side you can see the code coverage of the different classes. (Different IDEs have different way to check the code coverage)
There might be possibility that the test class you have written is not checking every condition in the apex class so you might need to modify the test class.
The ideal test class is always to check all the possible conditions of error handling not just to have code coverage.

Thank you
Lars CadeLars Cade
In my case, the code is a simple trigger to update a custom date field in an account when an activity is added with certain parameters. I'm having a hard time figuring out what a test class even is, let alone how to use it. The documentation I've been able to find is unclear on the subject. Can I even write test classes for triggers?
GauravGargGauravGarg
Hi Lars,

yes, you can write test classes for Trigger also.

Thanks,
Gaurav
Vishal ShelarVishal Shelar
Test class is basically a class where you create a dummy data and test your code on that data.
For example: your trigger does something whent the custome field is updated. So create a dummy test account in test class and then update the date field in that and check whether the trigger is running as expected.
This is general idea about the test class.
You have to write the test class for almost everything you do as custom(class, trigger etc).

Reference link : https://developer.salesforce.com/page/An_Introduction_to_Apex_Code_Test_Methods
 
Lars CadeLars Cade
Thanks for the answers so far. After following the instructions here (http://help.salesforce.com/HTViewSolution?id=000199478) the code coverage increased from 23% to 26%. However, I'm still unclear on how to determine which apex classes are lacking coverage. Should I contact the support teams for the managed packages I have installed if I find that they are to blame?
GauravGargGauravGarg
Lars, 

As far I have knowledge. Manage package can only be registered with salesforce when they have enough code coverage (75%) to deploy on someone's else org. Hence, contacting Manage Package support team would might not provide any help. We need to dig into your org and find out the classes / triggers which are causing this issue.

Thanks,
Gaurav