Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

My developer org's overall code coverage is 76%, but some classes are still 0% while others are 100%.

Will I be able to deploy all my code or does Salesforce require a 75% coverage per class?

share|improve this question
1  
Take particular note of "Every trigger must have some test coverage" i.e. greater than 0%. Otherwise its 75% across all the code. –  Keith C Jun 27 at 12:23
add comment

3 Answers 3

up vote 5 down vote accepted

It is just 75% total code coverage across your entire organization:

  • At least 75% of your Apex code must be covered by unit tests, and all of those tests must complete successfully. Note the following:
    • When deploying to a production organization, every unit test in your organization namespace is executed.
    • Calls to System.debug are not counted as part of Apex code coverage.
    • Test methods and test classes are not counted as part of Apex code coverage.
    • While only 75% of your Apex code must be covered by tests, your focus shouldn't be on the percentage of code that is covered. Instead, you should make sure that every use case of your application is covered, including positive and negative cases, as well as bulk and single records. This should lead to 75% or more of your code being covered by unit tests.
  • Every trigger must have some test coverage.
  • All classes and triggers must compile successfully.

It is important to continually check your code coverage. Also, make sure you are writing proper unit tests, this includes assert statements in each test class. You may also want to consider doing some branch coverage for your own peace of mind. You can read up on Testing Best Practices and How to Write Good Unit Tests for even more info.

share|improve this answer
1  
Stated differently, the entire organization must be at 75%, and each trigger must have at least one execution, which must cover at least one line of code. –  sfdcfox Jun 27 at 18:10
add comment

Yes, you should be able to deploy it. At least I have done so in the past.

However, my recommendation is to try to cover as much as possible, or as many use cases as possible for each class. Especially those 0% covered classes... Unit tests are your friends! :)

share|improve this answer
add comment

From the documentation

The deploy call completes successfully only if all of the following must be true. At least 75% of your Apex code must be covered by unit tests, and all of those tests must complete successfully. Note the following. When deploying to a production organization, every unit test in your organization namespace is executed. Calls to System.debug are not counted as part of Apex code coverage. Test methods and test classes are not counted as part of Apex code coverage. While only 75% of your Apex code must be covered by tests, your focus shouldn't be on the percentage of code that is covered. Instead, you should make sure that every use case of your application is covered, including positive and negative cases, as well as bulk and single records. This should lead to 75% or more of your code being covered by unit tests. Every trigger must have some test coverage. All classes and triggers must compile successfully.

This can be a bit cryptic I know. Basically, when you look at a class that is already in production, it may list it as having 0% class coverage, but this is generally not the case, you should try to recompile your classes and rerun the tests for those classes, that generally updates the code coverage.

In general the overall Code Coverage stat when you go to Apex Classes is not always all that accurate, and needs to be rerun frequently as it does not automatically update.

share|improve this answer
1  
I don't believe this is true - "In short, in order to deploy, each class that you are trying to deploy needs to have >75% coverage in order to deploy. So if you have a class in your sandbox org with 50% code coverage, then you are not going to be able to deploy to production." You can deploy classes with 0% code coverage as long as the average across the board is 75% or more. You could also just not include them in the deploy. –  Jesse Altman Jun 27 at 12:24
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.