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
Christopher PezzaChristopher Pezza 

Test Coverage Help

Heres my Class

public with sharing class nCino_CustomerHealth{
    //Declare Public Variables
    List<Customer_Health__c> myCHList;
    public Set<String> cmSet {get; set;}
    public Set<String> amset {get; set;}
    public Set<String> seset {get; set;}
    
    public String CSMFilter {get;set;}
    public String SEFilter {get;set;}
    public String AMFilter {get;set;}
    
    public nCino_CustomerHealth() {
    
    
    cmSet = new Set<String>();
    for(Customer_Health__c chc : [SELECT Customer_Success_Manager__c FROM Customer_Health__c WHERE Customer_Success_Manager__c <> ' ']){
             cmSet.add(chc.Customer_Success_Manager__c);
            }
    amset = new Set<String>();
    for(Customer_Health__c cha : [SELECT Account_Manager__c FROM Customer_Health__c WHERE Account_Manager__c <> ' ']){
             amset.add(cha.Account_Manager__c);
            }

    seset = new Set<String>();
    for(Customer_Health__c chs : [SELECT Support_Engineer__c FROM Customer_Health__c WHERE Support_Engineer__c <> ' ']){
             seset.add(chs.Support_Engineer__c);
            }

        myCHList = [SELECT  Id, 
                        Name, 
                        Account__r.Name,
                        Account__c,
                        Master_Scorecard__c, 
                        Survey_Score__c, 
                        Data_Storage__c, File_Storage__c, 
                        Avg_Stage_Duration__c,
                        Days_to_Close1__c,
                        Days_to_close2__c,
                        Pass_Through_Rate2__c,
                        Pass_Through_Rate1__c,
                        Account__r.Handed_over_to_support__c
                FROM Customer_Health__c WHERE Account__r.Current_Customer__c='Yes'];
    }

    public List<SelectOption> getCSMItems() {
        List<SelectOption> csmoptions = new List<SelectOption>();
        csmoptions.add(new SelectOption('No Filter', 'Customer Success Manager'));
        csmoptions.add(new SelectOption(' ', 'No CSM'));
        for (String s : cmSet) {
           
            csmoptions.add(new SelectOption(s, s));
        }
        system.debug('***' + csmoptions);
        return csmoptions;
    }

    public List<SelectOption> getSEItems() {
        List<SelectOption> seoptions = new List<SelectOption>();
        seoptions.add(new SelectOption('No Filter', 'Support Engineer'));
        seoptions.add(new SelectOption(' ', 'No SE'));
        for (String a : seset) {
            seoptions.add(new SelectOption(a, a));
        }
        system.debug('***' + seoptions);
        return seoptions;
    }

    public List<SelectOption> getAMItems() {
        List<SelectOption> amoptions = new List<SelectOption>();
        amoptions.add(new SelectOption('No Filter', 'Account Manager'));
        for (String d : amset) {
            amoptions.add(new SelectOption(d, d));
        }
        system.debug('***' + amoptions);
        return amoptions;
    }
    
    public void RefreshTable() {
        system.debug('*** RefreshTable1');
        if(CSMFilter == 'No Filter' && SEFilter == 'No Filter' && AMFilter == 'No Filter') {
            myCHList = [SELECT  Id, 
                        Name, 
                        Account__r.Name,
                        Account__c,
                        Master_Scorecard__c, 
                        Survey_Score__c, 
                        Data_Storage__c, File_Storage__c, 
                        Avg_Stage_Duration__c,
                        Days_to_Close1__c,
                        Days_to_close2__c,
                        Pass_Through_Rate2__c,
                        Pass_Through_Rate1__c,
                        Account__r.Handed_over_to_support__c
                FROM Customer_Health__c WHERE Account__r.Current_Customer__c='Yes'];
            system.debug('*** All No Filter: ' + CSMFilter + ' | ' + SEFilter + ' | ' + AMFilter);

        } else if (CSMFilter != 'No Filter') {
            myCHList = [SELECT  Id, 
                        Name, 
                        Account__r.Name,
                        Account__c,
                        Master_Scorecard__c, 
                        Survey_Score__c, 
                        Data_Storage__c, File_Storage__c, 
                        Avg_Stage_Duration__c,
                        Days_to_Close1__c,
                        Days_to_close2__c,
                        Pass_Through_Rate2__c,
                        Pass_Through_Rate1__c,
                        Account__r.Handed_over_to_support__c
                FROM Customer_Health__c WHERE Account__r.Current_Customer__c='Yes' AND
                                            Customer_Success_Manager__c = :CSMFilter];
            system.debug('*** CSMFilter ' + CSMFilter);
        } else if (SEFilter != 'No Filter') {
            myCHList = [SELECT  Id, 
                        Name, 
                        Account__r.Name,
                        Account__c,
                        Master_Scorecard__c, 
                        Survey_Score__c, 
                        Data_Storage__c, File_Storage__c, 
                        Avg_Stage_Duration__c,
                        Days_to_Close1__c,
                        Days_to_close2__c,
                        Pass_Through_Rate2__c,
                        Pass_Through_Rate1__c,
                        Account__r.Handed_over_to_support__c
                FROM Customer_Health__c WHERE Account__r.Current_Customer__c='Yes' AND
                                            Support_Engineer__c = :SEFilter];
            system.debug('*** SEFilter ' + SEFilter);
        } else if (AMFilter != 'No Filter') {
            myCHList = [SELECT  Id, 
                        Name, 
                        Account__r.Name,
                        Account__c,
                        Master_Scorecard__c, 
                        Survey_Score__c, 
                        Data_Storage__c, File_Storage__c, 
                        Avg_Stage_Duration__c,
                        Days_to_Close1__c,
                        Days_to_close2__c,
                        Pass_Through_Rate2__c,
                        Pass_Through_Rate1__c,
                        Account__r.Handed_over_to_support__c
                FROM Customer_Health__c WHERE Account__r.Current_Customer__c='Yes' AND
                                              Account_Manager__c= :AMFilter];
            system.debug('*** AMFilter ' + AMFilter);
        }
    }
    
    public List<Customer_Health__c> getCHList(){
        return myCHList;
    }    
    
    public Decimal getNewRelease() {
        AggregateResult[] groupedResults = [SELECT COUNT(ID)totalSum FROM Customer_Health__c 
                                            WHERE Account__r.Handed_over_to_Support__c=True 
                                            AND (nCino_Version__c LIKE '%1.6%')];
        Decimal totalACV = (Decimal)groupedResults[0].get('totalSum');
        AggregateResult[] groupedResults2 = [SELECT COUNT(ID)totalAcc FROM Customer_Health__c 
                                                            WHERE Account__r.Handed_over_to_Support__c=True];
        Decimal totalNum = (Decimal)groupedResults2[0].get('totalAcc');
        return (totalACV/totalNum)*100;
    }
    
    public Decimal getAvgScore() {
        AggregateResult[] groupedResults = [SELECT SUM(Master_Scorecard__c)totalSum FROM Customer_Health__c 
                                            WHERE Account__r.Handed_over_to_Support__c=True];
        Decimal totalAmount = (Decimal)groupedResults[0].get('totalSum');
        AggregateResult[] groupedResults2 = [SELECT COUNT(ID)totalN FROM Customer_Health__c 
                                                            WHERE Account__r.Handed_over_to_Support__c=True];
        Decimal totalNum = (Decimal)groupedResults2[0].get('totalN');
        return (totalAmount/totalNum);
    }
    
    public Decimal getAvgSat() {
        AggregateResult[] groupedResults = [SELECT SUM(Survey_Score__c)totalSum FROM Customer_Health__c 
                                            WHERE Account__r.Handed_over_to_Support__c=True];
        Decimal totalAmount = (Decimal)groupedResults[0].get('totalSum');
        AggregateResult[] groupedResults2 = [SELECT COUNT(ID)totalN FROM Customer_Health__c 
                                                            WHERE Account__r.Handed_over_to_Support__c=True];
        Decimal totalNum = (Decimal)groupedResults2[0].get('totalN');
        return (totalAmount/totalNum);
    }

    public Decimal getInformatica() {
        AggregateResult[] groupedResults = [SELECT COUNT(Data_Integration__c)totalSum FROM Customer_Health__c 
                                            WHERE Account__r.Handed_over_to_Support__c=True AND Data_Integration__c='Informatica'];
        Decimal totalAmount = (Decimal)groupedResults[0].get('totalSum');
        return totalAmount;
    } 
    
    public Decimal getAvgPTR() {
        AggregateResult[] groupedResults = [SELECT SUM(Pass_Through_Rate2__c)totalSum FROM Customer_Health__c 
                                            WHERE Account__r.Handed_over_to_Support__c=True];
        Decimal totalAmount = (Decimal)groupedResults[0].get('totalSum');
        AggregateResult[] groupedResults2 = [SELECT COUNT(ID)totalN FROM Customer_Health__c 
                                                            WHERE Account__r.Handed_over_to_Support__c=True];
        Decimal totalNum = (Decimal)groupedResults2[0].get('totalN');
        
        return (totalAmount/totalNum);
    }  
    
    public Decimal getDocMan() {
        AggregateResult[] groupedResults = [SELECT COUNT(HTML_DocMan__c)totalSum FROM Customer_Health__c 
                                            WHERE Account__r.Handed_over_to_Support__c=True AND (HTML_DocMan__c='Yes - Successfully' OR HTML_DocMan__c = 'Yes - Piloting')];
       Decimal totalAmount = (Decimal)groupedResults[0].get('totalSum');
        return totalAmount;
    } 
   
    public Decimal getSpreads() {
        AggregateResult[] groupedResults = [SELECT COUNT(Spr__c)totalSum FROM Customer_Health__c 
                                            WHERE Account__r.Handed_over_to_Support__c=True AND (Spr__c='Yes - Successfully' OR Spr__c = 'Yes - Piloting')];
        Decimal totalAmount = (Decimal)groupedResults[0].get('totalSum');
        return totalAmount;
    }
    
    public Decimal getLogin() {
        AggregateResult[] groupedResults = [SELECT SUM(of_Login__c)totalSum FROM Customer_Health__c 
                                            WHERE Account__r.Handed_over_to_Support__c=True];
        Decimal totalAmount = (Decimal)groupedResults[0].get('totalSum');
        AggregateResult[] groupedResults2 = [SELECT COUNT(ID)totalN FROM Customer_Health__c 
                                                            WHERE Account__r.Handed_over_to_Support__c=True];
        Decimal totalNum = (Decimal)groupedResults2[0].get('totalN');
        return (totalAmount/totalNum);
    }
    
    public Decimal getNumRecords() {
        AggregateResult[] groupedResults = [SELECT COUNT(Id)total FROM Customer_Health__c
                                            WHERE Account__r.Current_Customer__c='Yes'];
        Decimal totalValue = (Decimal)groupedResults[0].get('total');
        return totalValue;
        
    }

    public Decimal getAVGTotalLoans() {
        AggregateResult[] groupedResults = [SELECT COUNT(Id)Total FROM nBIA__BI_Data__c 
                                            WHERE nBIA__Unique_Name__c = 'AS: Loans' 
                                            AND nBIA__Start_Date__c = YESTERDAY];
        Decimal totalCount = (Decimal)groupedResults[0].get('Total');

        AggregateResult[] groupedResults1 = [SELECT SUM(nBIA__Count__c)summ FROM nBIA__BI_Data__c 
                                            WHERE nBIA__Unique_Name__c = 'AS: Loans' 
                                            AND nBIA__Start_Date__c = YESTERDAY];
        Decimal totalSum = (Decimal)groupedResults1[0].get('summ');

        Decimal avgloans;
        if (totalCount != 0) {
        avgloans = totalSum / totalCount;
        } else {
            avgloans = 0;
        }

        return avgloans;
    }

    public Decimal getAVGTotalAccounts() {
        AggregateResult[] groupedResults = [SELECT COUNT(Id)Total FROM nBIA__BI_Data__c 
                                            WHERE nBIA__Unique_Name__c = 'AS: Accounts' 
                                            AND nBIA__Start_Date__c = YESTERDAY];
        Decimal totalCount = (Decimal)groupedResults[0].get('Total');

        AggregateResult[] groupedResults1 = [SELECT SUM(nBIA__Count__c)summ FROM nBIA__BI_Data__c 
                                            WHERE nBIA__Unique_Name__c = 'AS: Accounts' 
                                            AND nBIA__Start_Date__c = YESTERDAY];
        Decimal totalSum = (Decimal)groupedResults1[0].get('summ');

        Decimal avgaccounts;
        if (totalCount != 0) {
        avgaccounts = totalSum / totalCount;
        } else {
            avgaccounts = 0;
        }

        return avgaccounts;
    }

    public Decimal getAVGReportsRun() {
        AggregateResult[] groupedResults = [SELECT nBIA__Data_Source_Name__c, SUM(nBIA__Count__c)TheSUM 
                                            FROM nBIA__BI_Data__c 
                                            WHERE nBIA__Unique_Name__c = 'AS: Reports Run' 
                                            AND nBIA__Start_Date__c = LAST_N_DAYS:7 
                                            GROUP BY nBIA__Data_Source_Name__c];

        Decimal TotalCount = 0;
        Decimal TotalSum = 0;
        Integer i;

        for (i = 0; i < groupedResults.size(); i++) {
            TotalCount++;
            TotalSum += (Decimal)groupedResults[i].get('TheSUM');
        }

        Decimal avgreportrun;
        if (TotalCount != 0) {
            avgreportrun = TotalSum / TotalCount;
        } else {
            avgreportrun = 0;
        }
        return avgreportrun;
    }

    public Decimal getAVGDaysToClose() {
        AggregateResult[] groupedResults = [SELECT nBIA__Data_Source_Name__c, SUM(nBIA__Count__c)TheSUM, 
                                                    COUNT(Id)NumOfLoans FROM nBIA__BI_Data__c 
                                            WHERE nBIA__Unique_Name__c = 'AS: Loans Days To Close' 
                                            AND nBIA__Count__c <> 0 
                                            GROUP BY nBIA__Data_Source_Name__c];

        Decimal TotalCount = 0;
        Decimal TotalLoans = 0;
        Decimal TotalSum = 0;
        Decimal TotalAvgDays = 0;
        Integer i;

        for (i = 0; i < groupedResults.size(); i++) {
            TotalCount++;
            TotalSum = (Decimal)groupedResults[i].get('TheSUM');
            TotalLoans = (Decimal)groupedResults[i].get('NumOfLoans');
            TotalAvgDays += TotalSum / TotalLoans;
        }

        Decimal avgdays = TotalAvgDays / TotalCount;
        if (TotalCount != 0) {
            avgdays = TotalAvgDays / TotalCount;
        } else {
            avgdays = 0;
        }

        return avgdays;
    }
   
}

Here is my Test Class so far

@isTest(SeeAllData=true)
private class nCino_CustomerHealthTest {
	
	@isTest static void test_method_one() {
		// Implement test code
		CHANNEL_ORDERS__Customer__c customer = new CHANNEL_ORDERS__Customer__c(CHANNEL_ORDERS__Customer_City__c = 'Wilmington', 
												CHANNEL_ORDERS__Customer_Company_Name__c = 'The New Bank',	
												CHANNEL_ORDERS__Customer_Country__c = 'US',	
												CHANNEL_ORDERS__Customer_Org_ID__c = '00DG0000000jN8k', 
												CHANNEL_ORDERS__Customer_State__c = 'NC', 
												CHANNEL_ORDERS__Customer_Street__c = '11 Main Street', 
												CHANNEL_ORDERS__Customer_ZIP_Postal_Code__c = '28411');

		insert(customer);

		Account a = new Account(Name='The New Bank', Type='Customer', Industry='Bank', BillingState='NC', Customer__c = customer.Id, nCino_Version__c='1.64.4', Customer_Success_Manager__c = '005a0000007l9zJ', Primary_Product_Specialist__c = '005a000000AIahS', OwnerId = '005a0000009B00f');

		insert(a);

		sfLma__License__c license = new sfLma__License__c(sfLma__Account__c = a.Id, 
														sfLma__Install_Date__c = system.today(),
														sfLma__License_Type__c = 'Editable',
														sfLma__Package_Version__c = 'a0Ra000000Ib1Vx',
														sfLma__Status__c = 'Active',
														sfLma__Subscriber_Org_ID__c = '00DG0000000jN8k',
														sfLma__Used_Licenses__c = 2);
 
 		insert(license);

		Customer_Health__c c = new Customer_Health__c(Account__c=a.Id);

		insert(c);


		nCino_CustomerHealth theTest = new nCino_CustomerHealth();
		System.assert(theTest.cmSet.contains(c.Customer_Success_Manager__c));
		System.assert(theTest.amSet.contains(c.Account_Manager__c));
		System.assert(theTest.seSet.contains(c.Support_Engineer__c));





	}

}

It seems to not like the asserts when they worked before. Any Ideas?
Best Answer chosen by Christopher Pezza
AshwaniAshwani
In the main class, can you check that you are receiving any record by the query. Also, you have set "@isTest(SeeAllData=true)".

Did you tried with "@isTest(SeeAllData=false)" or "@isTest" as you are creating test data.

All Answers

AshwaniAshwani
Hi Christopher,

Can you please explain the scenario which you want to create. It is difficult to read 300+ line of code to understand asserts.

However, you have not assigned any value to field "Customer_Success_Manager__c" in your test class line 30. You are simply using

Customer_Health__c c = new Customer_Health__c(Account__c=a.Id); // missing Customer_Success_Manager__c

So, in constructor empty result will be obtained for query over CMS_Health.
Christopher PezzaChristopher Pezza
That field is a formula field that looks up to the account record
AshwaniAshwani
In the main class, can you check that you are receiving any record by the query. Also, you have set "@isTest(SeeAllData=true)".

Did you tried with "@isTest(SeeAllData=false)" or "@isTest" as you are creating test data.

This was selected as the best answer