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
RepsGRepsG 

Code Coverage doesnt match in Different Sandboxs

I have Class which I have created a Testmethod for. In one sandbox my code coverage is 79%. When I test the same class (with the same testmethod) in another sanbox the code coverage drops to 69%.

 

In my testmethod i do not reference records that alreadty exist in the environment. I create all Standard/Custom recoreds that needed for the test in my testmethod.

 

When viewing the code to identify the lines that have not been tested, i can clearly see there are lines which have comments highlghted as red and line which have nothing at all also highlighted as red.

 

I have raised this with Salesforce Support and their response was:

 

Salesforce Response ----------------------------------------------------------------------------------------

I have ran the test in both sandboxes and found the difference of code coverage which you are getting is due to the queries like

"rmvcon = [select name, Firstname, Lastname, Salutation, Date_of_Birth__c, EDB_Customer_No__c,
                      OLB_User_Id__c, Disabled_Online_Banking_Date__c, Ex_Member_Of__c,
                      Town_of_Birth__c, Country_of_Birth__c, NationalInsuranceNumber__c,
                      Reason_for_leaving__c, Disabled_Contact__c, AccountId
                      from Contact
                      where id=:RmvId];" and some other conditional statements.

 

Please check this conditional statements and queries to find the difference in code coverage.

--------------------------------------------------------------------------------------------------------------------------

 

I dont understand the response.

 

Can anybody help?

Best Answer chosen by Admin (Salesforce Developers) 
RepsGRepsG

I found the solution.

 

Go into the org and in Apex Classes click on 'Clear Code Coverage'

 

Problem solved.