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
SeanCenoSeanCeno 

Change Set deployment issues

Hello All, I’m trying to deploy a new change set of 3 components:

 

Account_RollupTrades

Account_RollupTradesTest

Account_RollupTrades trigger

 

After clearing out all test history, running ALL tests multiple times, my code coverage in the Production org is 83%. Same goes for the sandbox (83%).

Account_RollupTrades has 100% code coverage with 27/27 test methods passed in the sandbox.

Account_RollupTrades trigger has 100% code coverage with 3/3 test methods passed.

All custom settings, fields, and workflows are accounted for in both orgs.

@isTest is set to (SeeAllData = True) because it’s at version 28.0.

Debug logs are not showing me anything of concern.

 

When trying to deploy to production, it fails because the overall code coverage drops to 74% (below the required 75%).

 

 

How is it that 1 class, 1 trigger, and 1 test class could drop an entire org’s code coverage by 9% when they have 100% coverage?

Have any of you heard of this issue before? Can a sandbox display incorrect code coverage data?

amarcuteamarcute

Hi,

 

Code Coverage Depends on many things.

 

Do you have any packages installed that could be skewing the results upwards? if you have any packages, there will be unit tests for  the classes in some of packages which may give you more coverage than the actual.

 

Also, You can Click on "Estimate Your Organization's code coverage" link on the Apex classes main page. The value you get here, will give you actual code coverage as it excludes code coverage of any managed packages.

SeanCenoSeanCeno

Hi amarcute,

 

I do have a couple packages, but I have been using the "Estimate Your Organization's Code Coverage" link so my results should be the actual code coverage without packages included.

 

My class has 104 lines, replacing the old version of the class of 240 lines. Could this drop in the number of lines cause the drop in coverage? I can post the code if needed...

amarcuteamarcute

Hi,

 

Its  may not be the number of lines. It may be due to missing setup, missing custom setting, need for extra mandatory fields or if you are using any code to create/update any records & in the target organization, if there are extra triggers/workflow etc which are not part of the source organization, there is a chance for less code coverage. Can enable the Debug Logs & check the logs if thereare any failures?

SeanCenoSeanCeno

I'm not sure what it was, but I was definitely missing something. I went back to the old code and edited it adding a new fund number and it deployed fine. Trying to change it to dynamic apex wasn't working for my test class.

 

Now I'm hitting a too many code statements in another class. Do you see a better way I write the mapping in this code?

 

public class Trades_CascadeAccounts {
    public Trades__c[] tradesOldList { set; get; }
    public Trades__c[] tradesNewList { set; get; }
    public Map<Id, Trades__c> tradesOldListMap { set; get; }
    
    public Trades_CascadeAccounts(Trades__c[] tradesOldList, Trades__c[] tradesNewList) {
        this.tradesNewList = tradesNewList == null ? new Trades__c[0] : tradesNewList.clone();
        this.tradesOldList = tradesOldList == null ? new Trades__c[0] : tradesOldList.clone();
        this.tradesOldListMap = new Map<Id, Trades__c>(this.tradesOldList);
    }
    
    public void execute() {
        Set<Id> tradesAccountIds = new Set<Id> {};
        for(Trades__c tradesNew : tradesNewList) {

			Trades__c tradesOld = tradesOldListMap.containsKey(tradesNew.Id) ? tradesOldListMap.get(tradesNew.Id) : new Trades__c();

			tradesAccountIds.addAll(new Set<Id> { tradesOld.Resolved_Firm_Trading_ID__c, tradesNew.Resolved_Firm_Trading_ID__c });
        }
		tradesAccountIds.remove(null);

        Account[] accountList = new Account[0];
        
        for(Id accountId : tradesAccountIds) {

			accountList.add(new Account(Id=AccountId,Rollup_Trades__c=null));
        }
        
        update accountList;
    }
}