+ Start a Discussion
Robert Robinson 48Robert Robinson 48 

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.
Best Answer chosen by Robert Robinson 48
Abhishek BansalAbhishek Bansal
Hi Robert,

Can you please check the below points in your test class:
  1. Make sure the seeAllData = false
  2. 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

vishal-negandhivishal-negandhi

Hi Robert, 

Can you also share your Test class please? That will help identify any issues. 

 

Thanks

Abhishek BansalAbhishek Bansal
Hi Robert,

Can you please check the below points in your test class:
  1. Make sure the seeAllData = false
  2. 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.
This was selected as the best answer
Robert Robinson 48Robert Robinson 48
Thank you. That knocked it out.
Abhishek BansalAbhishek Bansal
If this is working then please close this question by chooisng a best answer.