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
Kazuki KawamuraKazuki Kawamura 

When transferring from production environment to sandbox, Code coverage error occurs as soon as APEX code is verified.

I want to deploy an Apex class from sandbox to production.
The apex class has 88% code coverage in sandbox.
Is the code coverage in sandbox different from that in production?
User-added image
Best Answer chosen by Kazuki Kawamura
vaishali sharmavaishali sharma
No, code coverage should be 75%. If this error is occurring then there must be any dependent class on this which is affecting the code coverage. you need to check the code coverage of related classes. 

All Answers

vaishali sharmavaishali sharma
No, code coverage should be 75%. If this error is occurring then there must be any dependent class on this which is affecting the code coverage. you need to check the code coverage of related classes. 
This was selected as the best answer
Kazuki KawamuraKazuki Kawamura
Thank you for your reply.
 
Following your advice, I checked.
The class I want to deploy (hereinafter, this is called “classA”) calls 2 classes.
First class (hereinafter, this is called “classB”) is ordinary class and does not call any APEX class.
Second class (hereinafter, this is called “classC”) is exception class defined by me and does not call any APEX class.
Class B and C is already deployed to production.
Class B has 100% (36/36) code coverage by class B test in sandbox.
Class C has no test classes because of exception class, so is not calculated.
 
When class A test runs in sandbox, class A has 88% (134/152) code coverage, class B has 94% (34/36), class C’s code coverage is not displayed.
 
All code coverage except Class C which is exception class are above 75%.
 
Is it true that exception class has not to be tested?
Is anything I have to check?
Kazuki KawamuraKazuki Kawamura
I don’t know that Test class also has to been deployed.
By deploying Test classes, the code coverage problem is solved.
Thank you all.