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
nagendra kumar 21nagendra kumar 21 

Code coverage of 79% in sandbox but only 45% in production - won't deploy

Hi Everyone, Here i'm facing an issue while deploying my code to Prodection.
I'm a new Bee to SFDC, and i took forms help and others help i wrote a Test class, When i ran it in Dev Org i'm getting 79% code coverage but when i'm trying to deploy it to production it is showing code coverage was 45% as a Error, I have no clue why it is happening. Below i'm giving you my test code, please can any one check what is going on with my code.

@isTest(SeeAllData = False)
    public With Sharing class Test_AccountSalesviewTriggerHandler{
        
        static testMethod void testAccountSalesview_Create(){
    
            Account acc = CreateTestClassData.createCustomerAccount();
            acc.RecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByName().get('Water').getRecordTypeId();
            update acc;
            Salesview__c SV = CreateTestClassData.CreateSalesview();
            
            Test.StartTest();            
            List < Account_Salesview__c > lstsalesviewrecords = new List < Account_Salesview__c > ();
            
                for(Integer i=1; i<=10;i++){
                    Account_Salesview__c tempSV = new Account_Salesview__c();
                    tempSV.Name = 'ABC';
                    tempSV.SalesOrg_DistChann_Div_Cust__c = 'idexx123'+i ;                  
                    tempSV.Account__c = acc.Id;
                    tempSV.SalesView__c =  SV.Id;    
                    tempSV.Price_Group__c = 'DD';            
                    lstsalesviewrecords.add(tempSV);
                }
            insert lstsalesviewrecords;
            system.assertequals(acc.name,'Customer Testing Account'); 
            Test.StopTest();
        }
        
        static testMethod void testAccountSalesview_Update(){
    
            Account acc = CreateTestClassData.createCustomerAccount();
            acc.RecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByName().get('Water').getRecordTypeId();
            update acc;
            Salesview__c SV = CreateTestClassData.CreateSalesview();
            
            Test.StartTest();            
            List < Account_Salesview__c > lstsalesviewrecords = new List < Account_Salesview__c > ();           
            List < Account_Salesview__c > lstsalesviewrecordsupdate = new List < Account_Salesview__c > ();
            
            
                for(Integer i=1; i<=10;i++){
                    Account_Salesview__c tempSV = new Account_Salesview__c();
                    tempSV.Name = 'ABC';
                    tempSV.SalesOrg_DistChann_Div_Cust__c = 'idexx123'+i ;                  
                    tempSV.Account__c = acc.Id;
                    tempSV.SalesView__c =  SV.Id;                   
                    lstsalesviewrecords.add(tempSV);
                }
            insert lstsalesviewrecords; 
            Integer i = 0;
            for (Account_Salesview__c tempSV : lstsalesviewrecords){
                    
                    tempSV.Name = 'ABCD';
                    tempSV.SalesOrg_DistChann_Div_Cust__c = 'idexx1234'+i ;                  
                    tempSV.Account__c = acc.Id;
                    tempSV.SalesView__c =  SV.Id;                   
                    lstsalesviewrecordsupdate.add(tempSV);
                    i++;
                
            }
            update lstsalesviewrecordsupdate;
            system.assertequals(acc.name,'Customer Testing Account'); 
            Test.StopTest();
        }
        
        
        static testMethod void testAccountSalesview_Delete(){
    
            Account acc = CreateTestClassData.createCustomerAccount();
            //Account acc = CreateTestClassData.createCustomerAccount();
            acc.RecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByName().get('Water').getRecordTypeId();
            update acc;
            
            Salesview__c SV = CreateTestClassData.CreateSalesview();
            
            Test.StartTest();            
            List < Account_Salesview__c > lstsalesviewrecords = new List < Account_Salesview__c > ();
            
                for(Integer i=1; i<=10;i++){
                    Account_Salesview__c tempSV = new Account_Salesview__c();
                    tempSV.Name = 'ABC';
                    tempSV.SalesOrg_DistChann_Div_Cust__c = 'idexx123'+i ;                  
                    tempSV.Account__c = acc.Id;
                    tempSV.SalesView__c =  SV.Id;                   
                    lstsalesviewrecords.add(tempSV);
                }
            insert lstsalesviewrecords; 
            delete lstsalesviewrecords;
            system.assertequals(acc.name,'Customer Testing Account'); 
            Test.StopTest();
        }
    }
Swaraj Behera 7Swaraj Behera 7
Hi Nagendra,
Is 79% is the code coverage for the specific test class or the total org test coverage?
When you deploy your code to production it requires 75% over all code coverage.

Thanks
nagendra kumar 21nagendra kumar 21
Over all code coverage is 79%
 
Swaraj Behera 7Swaraj Behera 7
I think you are missing some test classes which is not there in production but is present in the Sandbox org which is making your sandbox code coverage as 79%.
 
nagendra kumar 21nagendra kumar 21
Swaraj, can you send me a draft mail please to nagendrap.0823@gmail.com