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

Hello,

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!

Thanks,
Nilesh
 
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.

https://developer.salesforce.com/forums/?id=906F0000000AdjwIAC

https://developer.salesforce.com/forums/?id=906F0000000kIlRIAU

https://developer.salesforce.com/forums/?id=906F0000000AeAeIAK

https://help.salesforce.com/articleView?id=000187272&language=en_US&type=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
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:
@istest
public class CaseOrderServiceClsTest {
    
    @istest    
    public static void runTestOne() {
        Id id = UserInfo.getUserId();
        User u = [Select id From User Where ID =: id];
        System.debug('Urse=>'+u);
        System.runAs(u){
        test.startTest();
        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 = c.id
        );
        report1.add(sr);
        insert report1;
        
         Service_Report__c sr1 = new Service_Report__c(
             Account__c = a.Id,
             Name = 'test 1',
             Source_Case__c = c.id
         );
        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 = c.id;
            insert sr2;
            
            
        
        CS_Trigger_Setting__c cs= new CS_Trigger_Setting__c(
            Name = 'updateOrder',
            Enabled__c=true
        );
        insert cs;
        
         CS_Trigger_Setting__c cs1 = new CS_Trigger_Setting__c(
             Name='OrderTrigger',
             Enabled__c=true
         );
        insert cs1;
        
        Order__c o = new Order__c(
            Name='test', 
            Case__c = c.Id, 
            AccountId__c = a.Id,
            Order_Type__c='Sales_Order',
            Service_Report__c = sr.id
        ); 
        insert o;
        
        Order__c o1 = new Order__c(
            Name='test', 
            Case__c = c.Id, 
            AccountId__c = a.Id,
            Service_Report__c =null, 
            Order_Type__c='Sales_Order'
        ); 
       insert o1;
        
        o.Service_Report__c = sr.id;
        update o;
        
        integer i= 1;
        System.debug('Case=> '+c);
        System.debug('Service Report =>'+sr);
        
        System.assertEquals(i,report1.size());
        CaseOrderServiceCls.fetchServiceRep(c.id);
        CaseOrderServiceCls.getNotLinkedOrderServices(c.id);
        CaseOrderServiceCls.getOrdersWithServices(c.Id);
        CaseOrderServiceCls.updateOrder(o.Id, sr.Id, c.Id);
        test.stopTest();
        }
    }   
    }



Thanks,
Nilesh