You need to sign in to do that
Don't have an account?
Code coverage in sandbox is 94% in Sandbox, 0% when promoted
I have the following Apex trigger in Sandbox:
public class New_Device_Opp_Controller {
@AuraEnabled
public static string createDeviceOpportunity(Id AccountrecId)
{
String returnValue = '';
List<Opportunity> oppList = new List<Opportunity>();
Opportunity oppObject = new Opportunity();
oppObject.Name = 'Do Not Delete';
oppObject.AccountId = AccountrecId;
oppObject.RecordTypeId = Schema.SObjectType.Opportunity.getRecordTypeInfosByName().get('Device Consulting').getRecordTypeId();
oppObject.StageName = 'Qualification';
Date closeDate = system.today();
oppObject.CloseDate = closeDate;
oppList.add(oppObject);
if(!oppList.isEmpty())
{
Database.SaveResult[] a = Database.insert(oppList, false);
if(a[0].isSuccess())
{
returnValue = oppList[0].id;
}
else
{
returnValue = 'failure';
}
}
return returnValue;
}
}
My Test class provides 94% coverage in the sandbox
When I attempt to promote, I select the "Run Specified Tests" becuase our consultants left us with garbage classes to clean up (another story for another day). When I run the specific test, I get this error:
Code Coverage Failure
Your code coverage is 0%. You need at least 75% coverage to complete this deployment.
New_Device_Opp_Controller
How can I clear this error? Thanks.
public class New_Device_Opp_Controller {
@AuraEnabled
public static string createDeviceOpportunity(Id AccountrecId)
{
String returnValue = '';
List<Opportunity> oppList = new List<Opportunity>();
Opportunity oppObject = new Opportunity();
oppObject.Name = 'Do Not Delete';
oppObject.AccountId = AccountrecId;
oppObject.RecordTypeId = Schema.SObjectType.Opportunity.getRecordTypeInfosByName().get('Device Consulting').getRecordTypeId();
oppObject.StageName = 'Qualification';
Date closeDate = system.today();
oppObject.CloseDate = closeDate;
oppList.add(oppObject);
if(!oppList.isEmpty())
{
Database.SaveResult[] a = Database.insert(oppList, false);
if(a[0].isSuccess())
{
returnValue = oppList[0].id;
}
else
{
returnValue = 'failure';
}
}
return returnValue;
}
}
My Test class provides 94% coverage in the sandbox
When I attempt to promote, I select the "Run Specified Tests" becuase our consultants left us with garbage classes to clean up (another story for another day). When I run the specific test, I get this error:
Code Coverage Failure
Your code coverage is 0%. You need at least 75% coverage to complete this deployment.
New_Device_Opp_Controller
How can I clear this error? Thanks.
Can you please check the below points in your test class:
- Make sure the seeAllData = false
- No id should be hard coded
It would be good if you can share the test class code as well. Or if possible please contact me direclty on:Gmail: abhibansal2790@gmail.com
Skype: abhishek.bansal2790
I will help you to fix this issue.
Thanks,
Abhishek Bansal.
All Answers
Hi Robert,
Can you also share your Test class please? That will help identify any issues.
Thanks
Can you please check the below points in your test class:
- Make sure the seeAllData = false
- No id should be hard coded
It would be good if you can share the test class code as well. Or if possible please contact me direclty on:Gmail: abhibansal2790@gmail.com
Skype: abhishek.bansal2790
I will help you to fix this issue.
Thanks,
Abhishek Bansal.