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
Rajendra MukkaRajendra Mukka 

Batch class with enough coverage in full sandbox failed during Production deployment.

Error Message:
Code Coverage Failure
Your code coverage is 12%. You need at least 75% coverage to complete this deployment.
 
Vinuthh SVinuthh S
Hi Rajendra

Check all the fields used in the batch class are in production also and try to get 90% Code coverage in the sandbox and move the code into production.

Thanks 
Vinuthh S
Amit Chaudhary 8Amit Chaudhary 8
It is just 75% total code coverage across your entire organization:
  1. 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.
  1. Every trigger must have some test coverage.
  2. All classes and triggers must compile successfully.
*******************************

If I have a deployment that fails like this I do the following
1. Run all tests in production.
You may have tests that are failing, commonly due to the addition of a new validation rule (among a million other reasons). If this is the case take steps to fix the test failures, such as turning off the offending validation rules, until you're able to get your code coverage up enough for you to deploy.

2. Run all tests in the source org
It's possible that you're deployment is causing test to fail. Running all tests in the source sandbox will let you know if that's the case. Once you fix the failures in the sandbox and confirm you've got enough code coverage build a new change set and redeploy.

3. Deploy Class with test class
If you're still getting good test coverage on both sides you'll need to dig a little harder. Try to deploy same class with test class.