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
Girbson Bijou 8Girbson Bijou 8 

Code Coverage Production Vs Sandbox

Hi All,
I have a class where the Coverage is 91% in  a sandbox. But, when  I am deploying it to the production, i received  code Coverage error  and it is 0%. Where do you think the problem is. 

Best, 
Best Answer chosen by Girbson Bijou 8
Abhishek BansalAbhishek Bansal
Hi Girbson,

It is not recommended to use seeAllData as true, can you please set it to False and try to ceate the data in your test class itself. In this  way you will get the right coverage in both the sandbox and production. Please let me know if you need any help in creating the test data.

Thanks,
Abhishek Bansal.

All Answers

Abhishek BansalAbhishek Bansal
seeAllData is true or false?
AnudeepAnudeep (Salesforce Developers) 
Why Code Coverage Numbers Differ Between Sandbox and Production

When Apex is deployed to production or uploaded as part of a package to the Salesforce AppExchange, Salesforce runs local tests in the destination organization. Sandbox and production environments often don’t contain the same data and metadata, so the code coverage results don’t always match. If code coverage is less than 75% in production, increase the coverage to be able to deploy or upload your code. The following are common causes for the discrepancies in code coverage numbers between your development or sandbox environment and production. This information can help you troubleshoot and reconcile those differences.

I recommend reviewing the following documentation

If you find this information helpful, please mark this answer as Best. It may help others in the community. Thank You!
Girbson Bijou 8Girbson Bijou 8
Hi Abhishek, 
seeAllData is true
 
Abhishek BansalAbhishek Bansal
Hi Girbson,

It is not recommended to use seeAllData as true, can you please set it to False and try to ceate the data in your test class itself. In this  way you will get the right coverage in both the sandbox and production. Please let me know if you need any help in creating the test data.

Thanks,
Abhishek Bansal.
This was selected as the best answer
Girbson Bijou 8Girbson Bijou 8
Hi Abhishek, 
I put seeAllData as false and i still have 0% coverage in the production. I want to notice that the class has an invocable method which is used in a process builder. 
 
Abhishek BansalAbhishek Bansal
You need to create test data in the test class. After putting seeAllData as false, you will see the same coverage i.e. 0% in the sandbox as well, so please create test data and then check the coverage. For any further help, you can reach out to me directly: Gmail: abhibansal2790@gmail.com Skype: abhishek.bansal2790 Thanks.