You need to sign in to do that
Don't have an account?

Code Coverage Failure When deploying trigger from Sandbox to Production
Hi,
I have created following APEX TRIGGER so that whenever a new job is created on SalesForce, a Task is created on JIRA CORE.
trigger JobTrigger on Contract (after insert, after update) {
if (Trigger.isInsert && Trigger.isAfter) {
JCFS.API.createJiraIssue('10000', '10100');
}
if (Trigger.isUpdate && Trigger.isAfter) {
JCFS.API.pushUpdatesToJira();
}
}
Now when I deploy this trigger from Sandbox to Production, I get following error:
Code Coverage Failure
Your organization's code coverage is 0%. You need at least 75% coverage to complete this deployment. Also, the following triggers have 0% code coverage. Each trigger must have at least 1% code coverage.
- JobTrigger
So can anyone help me how can I resolve this error that I can deploy this trigger to Production from Sandbox without any error?
Thanks,
Nitin.
I have created following APEX TRIGGER so that whenever a new job is created on SalesForce, a Task is created on JIRA CORE.
trigger JobTrigger on Contract (after insert, after update) {
if (Trigger.isInsert && Trigger.isAfter) {
JCFS.API.createJiraIssue('10000', '10100');
}
if (Trigger.isUpdate && Trigger.isAfter) {
JCFS.API.pushUpdatesToJira();
}
}
Now when I deploy this trigger from Sandbox to Production, I get following error:
Code Coverage Failure
Your organization's code coverage is 0%. You need at least 75% coverage to complete this deployment. Also, the following triggers have 0% code coverage. Each trigger must have at least 1% code coverage.
- JobTrigger
So can anyone help me how can I resolve this error that I can deploy this trigger to Production from Sandbox without any error?
Thanks,
Nitin.
Could you try creating an Account first in that test method?
All Answers
Greetings to you!
As mentioned your code coverage should be greater than 75% to deploy. Did you include the test class while deploying the trigger? It is necessary to include the test class.
Unit tests must cover at least 75% of your Apex code, and all of those tests must complete successfully.
Note the following:
Please refer to the below links which might help you further.
https://trailhead.salesforce.com/en/content/learn/modules/apex_testing/apex_testing_triggers
https://medium.com/@krissparks/apex-trigger-test-coverage-e78d801e9c7d
https://help.salesforce.com/articleView?id=000335222&type=1&mode=1 (https://help.salesforce.com/articleView?id=000335222&type=1&mode=1)
I hope it helps you.
Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.
Thanks and Regards,
Khan Anas
@isTest public class JobTriggerTest {
@isTest public static void contractAfterInsertTest(){
Contract job = new Contract( Name='My Test Job', Status = 'Draft', AccountID = '001g000002ADUj2' ) ;
Insert job;
}
}
What else I need to do to fix this error?
For that specific test class, you may want to create an account record in the test, then create the contract record looking up to that account.
See this screen shot.
Try opening Apex classes in your org. And click compile all classes. And secondly, try Run all from the developer console. This should solve your problem.
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Ajay Dubedi
www.ajaydubedi.com
Could you try creating an Account first in that test method?
Also, I would like to thank everyone who helped me to resolve this issue.