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
NM AdminNM Admin 

Stuck on deployment - Code Coverage Failure Issue


Need your suggestion if anybody faced smilar issue before.

Since the last couple of days facing an issue while validating changeset on production. I tried almost all ways from my end but not able to tackle the issue yet. Please share your suggestions, if any.

I have an apex class which is 96% cover without any failure on sandbox.
When I am trying to validate the same with its test class on the production I am getting an error like below:
User-added image

I am passing the Case Id to the method and used it to filter in the SOQL of its custom child object called "Service Report". This query results in empty using the 'Case Id' on Production only. I am not facing this issue in the sandbox.  
Production's overall coverage is 85%.

Debug from the production:
User-added image

Hopes to hear back from you!
Welcome to your suggestions!

Khan AnasKhan Anas (Salesforce Developers) 
Hi Nilesh,

Greetings to you!

Please refer to the below links which might help you further with the above issue.

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
Sitanshu TripathiSitanshu Tripathi
Will You please send your test class here?
Maybe you are using the hard code Id of any object record. If yes then you have to create a record inside the test class after that use that Id in your query.
NM AdminNM Admin
Hi Sitanshu,

Here is My test class:
public class CaseOrderServiceClsTest {
    public static void runTestOne() {
        Id id = UserInfo.getUserId();
        User u = [Select id From User Where ID =: id];
        String s ='{';
        Account a = new Account(
          Name = 'test'
        insert a;
        Case c = new Case(
          Subject = 'test',
            AccountId = a.Id,
            Type='Field Service',
            Status = 'New'
        insert c;
        List<Service_Report__c> report1 = new List<Service_Report__c>();
        Service_Report__c sr = new Service_Report__c(
          Account__c = a.Id,
            Name = 'test',
            Source_Case__c = c.Id,
            case__c =
        insert report1;
         Service_Report__c sr1 = new Service_Report__c(
             Account__c = a.Id,
             Name = 'test 1',
             Source_Case__c =
        insert sr1;
        Service_Report__c sr2 = new Service_Report__c();
            sr2.Account__c = a.Id;
            sr2.Name = 'All';
            sr2.Source_Case__c = c.Id;
            sr2.case__c =;
            insert sr2;
        CS_Trigger_Setting__c cs= new CS_Trigger_Setting__c(
            Name = 'updateOrder',
        insert cs;
         CS_Trigger_Setting__c cs1 = new CS_Trigger_Setting__c(
        insert cs1;
        Order__c o = new Order__c(
            Case__c = c.Id, 
            AccountId__c = a.Id,
            Service_Report__c =
        insert o;
        Order__c o1 = new Order__c(
            Case__c = c.Id, 
            AccountId__c = a.Id,
            Service_Report__c =null, 
       insert o1;
        o.Service_Report__c =;
        update o;
        integer i= 1;
        System.debug('Case=> '+c);
        System.debug('Service Report =>'+sr);
        CaseOrderServiceCls.updateOrder(o.Id, sr.Id, c.Id);