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
Spencer_BerkSpencer_Berk 

I'm trying to validate and deploy a apex class I created but am receiving Code Coverage Failure errors

I'm trying to validate and deploy an apex class via change sets that I created but am receiving Code Coverage Failure errors. The validation tests ran a total of 15,994 apex tests but 1,521 came back with errors. Do all these apex test failture errors need to be resolved before deploying the apex class? There is also at least one trigger with 0% code coverage "TDTM_AccountSoftCredit".
 
public class ApexToolkitDemo {

public static void sendEnvelopeMethod() {

Id mySourceId; // The ID of the initiating Salesforce object.

// Create an empty envelope.

dfsle.Envelope myEnvelope = dfsle.EnvelopeService.getEmptyEnvelope(

new dfsle.Entity(mySourceId));

// The initiating Salesforce entity.

// Use myEnvelope for later
// Use a Salesforce contact record as a Recipient here

Contact myContact = [SELECT Id, Name, Email FROM Contact LIMIT 1];

// Use the Recipient.fromSource method to create the Recipient

dfsle.Recipient myRecipient = dfsle.Recipient.fromSource(

myContact.Name, // Recipient name

myContact.Email, // Recipient email

null, // Optional phone number

'Signer 1', // Role Name. Specify the exact role name from template

new dfsle.Entity(myContact.Id)); // Source object for the Recipient

// Add Recipient to the Envelope

myEnvelope = myEnvelope.withRecipients(new List<dfsle.Recipient> { myRecipient });

// myTemplateId contains the DocuSign ID of the DocuSign Template

dfsle.UUID myTemplateId = dfsle.UUID.parse('93869f33-c73d-4344-919f-098707209002');

// Create a new document for the Envelope

dfsle.Document myDocument = dfsle.Document.fromTemplate(

myTemplateId, // The templateId in dfsle.UUID format

'myTemplate'); // Name of the template

// Add document to the Envelope

myEnvelope = myEnvelope.withDocuments(new List<dfsle.Document> { myDocument });

// Send the envelope

myEnvelope = dfsle.EnvelopeService.sendEnvelope(

myEnvelope, // The envelope to send

true); // Send now

}
}

I am not a developer so any help or guidance would be greatly appreciated.

 
SwethaSwetha (Salesforce Developers) 
HI Spencer,
When deploying an Apex class in Salesforce, it is required to have a minimum code coverage of 75%. If the validation tests fail to meet this requirement, the deployment will fail.

In your case, the validation tests ran a total of 15,994 apex tests, but 1,521 came back with errors. To address the Code Coverage Failure errors and successfully deploy the Apex class, you will need to resolve the test failure errors.

Note that all the Apex test failure errors do not necessarily need to be resolved before deploying the Apex class. However, you need to ensure that the overall code coverage is at least 75% and that there are no specific test classes that have a failure rate of 0%.

To resolve the Code Coverage Failure errors, you can follow these steps:
> Identify the specific test classes that are failing and causing the low code coverage. Review the error messages and stack traces to understand the cause of the failures.
> Update the failing test classes to fix the errors. This may involve modifying the test data, adjusting the test logic, or addressing any issues with the code being tested.
> Rerun the tests to verify that the failures have been resolved and that the overall code coverage meets the minimum requirement of 75%.

Once the code coverage is sufficient and all test failures have been resolved, you can proceed with deploying the Apex class via change sets.

Regarding the trigger with 0% code coverage ("TDTM_AccountSoftCredit"), it is crucial to create a test class that covers the trigger. This test class should include test methods that exercise the trigger's functionality and ensure that it is properly tested. By doing so, you can increase the code coverage for the trigger and address the 0% code coverage issue.

See related:
Code Coverage Best Practices
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_code_coverage_best_pract.htm
 
Checking Code Coverage
https://help.salesforce.com/articleView?id=code_dev_console_tests_coverage.htm&type=5
 
Deployment-related code coverage issues
https://help.salesforce.com/articleView?id=000335222&type=1&mode=1
 
https://salesforce.stackexchange.com/questions/148894/help-required-to-get-full-code-covered-in-test-class

https://salesforce.stackexchange.com/questions/317795/salesforce-code-coverage-failure-cannot-deploy-apex-trigger-in-production-despi

If this information helps, please mark the answer as best. Thank you