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
sivanovsivanov 

Salesforce test classes failing

Hello,
Our company is trying to deploy Apex code for the first time from sandbox to production. I read in your docs that you need to have 75% coverage or above to deploy. When I run validation, it seems like a lot of test cases that we didn't write (I'm guessing they are Salesforce tests) are failing, and seem to have lower than 100% coverage. I am guessing this is also pulling our overall coverage down. Is there anyone who could point me in the right direction for how to get these tests cases to pass so that I could deploy?

Here's an example of a test failure in a class that is also not written by us:
Class: AttachmentsToFilesControllerTest
Method: migrationBatchRunStandardUser
Errors: NAMForbiddenException: You don't have permission to access these fields on ContentVersion. Ask your Salesforce admin for help.

Any ideas why so many of these built-in classes have such low coverage and seem to be failing?
I have attached a screenshot of the dev console after I run tests on sandbox:
Built in Salesforce test cases failing
Best Answer chosen by sivanov
Dinesh MultaniDinesh Multani
It seems you don't have access to fields but from the image provided we are clear which object the error is for. If you are able to view the object name then just go to its fields and make sure you provide visibility access for all the fields of that object. Also, since you are taking apex code from Sandbox to Production just make sure that you have the Apex test code for the Class that you are deploying and while deploying it in Production select option "Run Specified Test" and provide the name of the test class for your Apex code; what this will do is it only run the test class for Apex code you are deploying bypassing the rest of the classes and if the coverage is more than 75 % then your class will be successfully deployed.

All Answers

Dinesh MultaniDinesh Multani
It seems you don't have access to fields but from the image provided we are clear which object the error is for. If you are able to view the object name then just go to its fields and make sure you provide visibility access for all the fields of that object. Also, since you are taking apex code from Sandbox to Production just make sure that you have the Apex test code for the Class that you are deploying and while deploying it in Production select option "Run Specified Test" and provide the name of the test class for your Apex code; what this will do is it only run the test class for Apex code you are deploying bypassing the rest of the classes and if the coverage is more than 75 % then your class will be successfully deployed.
This was selected as the best answer
sivanovsivanov
Thanks for the quick reply Dinesh!

I did as you said and supplied a comma-separated list of tests to run and it worked line a charm for me and I was able to deploy. Thanks for the help!