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
Laura KeetonLaura Keeton 

How to get code coverage for variables in switch cases

I'm very new to Saleforce development and have a problem with code coverage.  I'm using a switch case but can't get code coverage for the result variables.

Class:
public with sharing class cBannerManagedByReseller
{

    Public list<Banner_Managed_By_Reseller__c> lstPB = new list<Banner_Managed_By_Reseller__c>();
    Public list<Merchant_Risk_Summary__c> lstRisk = new list<Merchant_Risk_Summary__c>();
    Public List<Account> acct;  
    Public string acctID;
    Public string StatusBGColor{get;set;}
    Public string StatFontColor {get;set;}
    Public string AcctRankingBGColor{get;set;}
    Public string ARFontColor {get;set;}
    Public string qryStatus {get;set;}
    Public string qryAcctRanking {get;set;}
     
    public Id accountId {get; set;}

    public cBannerManagedByReseller(ApexPages.StandardController stdController) 
    {
        this.accountId= stdController.getId();
    }
 
    public List<Account> getAcct() 
    {
        list<Account> acct = [Select Id, Name, Organization__c, Industry, Organization__r.Partnership_Type__c, Phone, Account_Ranking__c, CardConex_Status__c FROM Account WHERE Id =:accountId limit 1];
        
        for (Account accts: acct)
        {
           qryStatus = accts.CardConex_Status__c;
           qryAcctRanking = accts.Account_Ranking__c;
        }    
            switch on (qryStatus) 
            {
                when 'Risk - Funds on hold', 'Risk - Sent to Collections', 'Risk - Levy Hold', 'Risk - Reserve', 'NA - *NOT OWNED BY BLUEFIN*', 'ACH Reject', 'Approved on hold per Underwriting', 'Capped Account'
                {      
                    StatusBGColor = 'Yellow';
                    StatFontColor = 'Red';  
                }  
                
                When 'Declined', 'Declined for Fraud'    
                {
                    StatusBGColor = 'Gray';
                    StatFontColor = 'White';
                }            

                when 'Withdrawn'
                {       
                    StatusBGColor= 'Blue';
                    StatFontColor = 'White';  
                }
                
                when 'Active'
                {       
                    StatusBGColor= '#ADD8E6';  //Light Blue
                }

                when 'SMAP Account'
                {       
                    StatusBGColor= '#FF1493';  //Deep Pink
                    StatFontColor = 'White';
                }

                when 'Headquarters situation - multiple accounts tied together'
                {
                    StatusBGColor = '#8A2BE2';
                    StatFontColor = 'White';            
                }
                
                when 'Bora Payments Account'
                {
                    StatusBGColor = '#ADFF2F';
                } 
                           
                when 'Mindbody-Supported Account'
                {
                    StatusBGColor = 'Orange';
                }

                when 'Bankruptcy'
                {
                    StatusBGColor = 'Black';
                    StatFontColor = 'White'; 
                }

                when 'Closed', 'Seasonal Close', 'Seasonal Merchant'  
                {       
                    StatusBGColor= 'Red';  //Tannish Orange
                }
                
                when 'Approved on ACH Delay' 
                {       
                    StatusBGColor= 'Olive';  
                    StatFontColor = 'White';
                }

                when 'P2PE Merchant' 
                {       
                    StatusBGColor= '#20B2AA';  //Light Seagreen (Turquiose)
                }


                when 'Decryptx Merchant' 
                {       
                    StatusBGColor= '#4B0082';  //Indigo Dark Purple)
                }

                when 'Live Test Account'
                {       
                    StatusBGColor= '#ADFF2F';   //Bright Bright Green
                }
                
                when 'Sales Order Account Page'
                {       
                    StatusBGColor= '#ADFF2F';   //Purple
                    StatFontColor = 'White';
                }            

                when else 
                {       
                    StatusBGColor= 'Blue';  
                    StatFontColor = 'White';
                } 
        
            }
               
            switch on (qryAcctRanking) 
            {
                when 'VIP', 'Tier II - High Processing Merchant', 'Tier III - High Processing Merchant'
                {      
                    AcctRankingBGColor= 'LightGreen';  //Light Green
                    ARFontColor = 'Black';  
                }  
                 
                when 'Tulsa TOP 100', 'Managed By Nathan Steinmetz', 'Managed by Linda Chastain'
                {       
                    AcctRankingBGColor= 'blue';
                }
               
                when 'Gateway Only' 
                {       
                    AcctRankingBGColor = 'DeepSkyBlue';     //Bright Blue
                }
                
                when else 
                {       
                    AcctRankingBGColor = 'Blue';  
                    ARFontColor = 'White';
                }  
            }
        return acct;
    }

    public List<Banner_Managed_By_Reseller__c> getlstPB() 
    {
        list<Banner_Managed_By_Reseller__c> lstPB = [SELECT Id, Name, Account_ID__c, Contact_Email__c, Contact_Phone__c, Background_Color__c, Font_Color__c, Message__c FROM Banner_Managed_By_Reseller__c WHERE Account_ID__c=:accountId limit 1];
        return lstPB;
    }
  
    public List<Merchant_Risk_Summary__c> getlstRisk() 
    {
        list<Merchant_Risk_Summary__c> lstRisk = [SELECT Id, Name, Account__c, Rules_Triggered__c FROM Merchant_Risk_Summary__c WHERE Account__c=:accountId limit 1];
        return lstRisk;
        
    } 
  
}


Test Class:
@isTest
public class cBannerManagedByResellerTest 
{
       
    static testmethod void MyTest()
    {        
       cBannerManagedByResellerTest banner = new cBannerManagedByResellerTest();
        Account a = new Account();
        a.name='Test Company1';
        a.CardConex_Status__c='Active';
        a.Account_Ranking__c='VIP';
        insert a;
        //return acct; 
        //Add the organization
        Banner_Managed_By_Reseller__c b = new Banner_Managed_By_Reseller__c();
        b.Account_ID__c = a.Id;
        b.Background_Color__c='Blue';
        b.Font_Color__c='White';
        b.Contact_Email__c = 'anyname@gmail.com';
        b.Contact_Phone__c = '1234567890';
        insert b;
        System.assert(b != null);

        //The the Merchant Risk object  
        Merchant_Risk_Summary__c r = new Merchant_Risk_Summary__c();
        r.account__c = a.ID;
        r.Comment__c = 'This is a test';
        r.Risk_Profile__c = 'a0SU00000003WxfMAE';
        insert r;
        system.assert(r !=null);
        
        PageReference pageRef = Page.BannerManagedByReseller;
        pageRef.getparameters().put('Account_ID__c', a.id);  
        Test.setCurrentPage(pageRef);
        Apexpages.StandardController sc = new Apexpages.StandardController(b);

        cBannerManagedByReseller ext = new  cBannerManagedByReseller(sc);         
        List<Banner_Managed_By_Reseller__c> lstB = ext.getlstPB();
        List<Account> lstA = ext.getAcct();
        List<Merchant_Risk_Summary__c> lstM = ext.getlstRisk();
        System.assert(ext.lstPB  != null);
        
        list<Account> acct = [Select Id, Name, Organization__c, Industry, Organization__r.Partnership_Type__c, Phone, Account_Ranking__c, CardConex_Status__c FROM Account];

        for (Account accts: acct)
        {
            string qryStatus = null;
             string qryAcctRanking = null;
            string ABFontColor = null;
            string AcctRankingBGColor = null;
            string StatusBGColor = null;
            string StatFontColor = null;

            system.assertEquals(null, qryStatus);
            system.assertEquals(null, qryAcctRanking);
            system.assertEquals(null, ABFontColor);
            system.assertEquals(null, AcctRankingBGColor);
            system.assertEquals(null, StatusBGColor);
            system.assertEquals(null, StatFontColor);
            
            qryStatus = 'Active';
            qryAcctRanking = 'VIP';
        }    
        
            string qryStatus = 'Active';
             string qryAcctRanking = 'VIP';
            string ABFontColor = null;
            string AcctRankingBGColor = null;
            string StatusBGColor = null;
            string StatFontColor = null;

            system.assertEquals('Active', qryStatus);
            system.assertEquals('VIP', qryAcctRanking);
            system.assertEquals(null, ABFontColor);
            system.assertEquals(null, AcctRankingBGColor);
            system.assertEquals(null, StatusBGColor);
            system.assertEquals(null, StatFontColor);
    
        switch on (qryStatus) 
         {
                when 'Risk - Funds on hold', 'Risk - Sent to Collections', 'Risk - Levy Hold', 'Risk - Reserve', 'NA - *NOT OWNED BY BLUEFIN*', 'ACH Reject', 'Approved on hold per Underwriting', 'Capped Account'
                {      
                    StatusBGColor = 'Yellow';
                    StatFontColor = 'Red';  
                }  
                
                When 'Declined', 'Declined for Fraud'    
                {
                    StatusBGColor = 'Gray';
                    StatFontColor = 'White';
                }            

                when 'Withdrawn'
                {       
                    StatusBGColor= 'Blue';
                    StatFontColor = 'White';  
                }
                
                when 'Active'
                {       
                    StatusBGColor= '#ADD8E6';  //Light Blue
                }

                when 'SMAP Account'
                {       
                    StatusBGColor= '#FF1493';  //Deep Pink
                    StatFontColor = 'White';
                }

                when 'Headquarters situation - multiple accounts tied together'
                {
                    StatusBGColor = '#8A2BE2';
                    StatFontColor = 'White';            
                }
                
                when 'Bora Payments Account'
                {
                    StatusBGColor = '#ADFF2F';
                } 
                           
                when 'Mindbody-Supported Account'
                {
                    StatusBGColor = 'Orange';
                }

                when 'Bankruptcy'
                {
                    StatusBGColor = 'Black';
                    StatFontColor = 'White'; 
                }

                when 'Closed', 'Seasonal Close', 'Seasonal Merchant'  
                {       
                    StatusBGColor= 'Red';  //Tannish Orange
                }
                
                when 'Approved on ACH Delay' 
                {       
                    StatusBGColor= 'Olive';  
                    StatFontColor = 'White';
                }

                when 'P2PE Merchant' 
                {       
                    StatusBGColor= '#20B2AA';  //Light Seagreen (Turquiose)
                }


                when 'Decryptx Merchant' 
                {       
                    StatusBGColor= '#4B0082';  //Indigo Dark Purple)
                }

                when 'Live Test Account'
                {       
                    StatusBGColor= '#ADFF2F';   //Bright Bright Green
                }
                
                when 'Sales Order Account Page'
                {       
                    StatusBGColor= '#ADFF2F';   //Purple
                    StatFontColor = 'White';
                }            

                when else 
                {       
                    StatusBGColor= 'Blue';  
                    StatFontColor = 'White';
                } 
        
            }
               
            switch on (qryAcctRanking) 
            {
                when 'VIP', 'Tier II - High Processing Merchant', 'Tier III - High Processing Merchant'
                {      
                    AcctrankingBGColor= 'LightGreen';  //Light Green
                    ABFontColor = 'Black';  
                }  
                 
                when 'Tulsa TOP 100', 'Managed By Nathan Steinmetz', 'Managed by Linda Chastain'
                {       
                    AcctRankingBGColor= 'blue';
                }
               
                when 'Gateway Only' 
                {       
                    AcctRankingBGColor = 'DeepSkyBlue';     //Bright Blue
                }
                
                when else 
                {       
                    AcctRankingBGColor = 'Blue';  
                    ABFontColor = 'White';
                }            
            }
        System.AssertEquals(true, AcctRankingBGColor !=Null);
        System.AssertEquals(true, ABFontColor !=Null);
        

    }
}
VamsiVamsi
Hi,

Change the below line from

        Apexpages.StandardController sc = new Apexpages.StandardController(b);

To 

        Apexpages.StandardController sc = new Apexpages.StandardController(a);

Please mark as  best answer if the above helps ..!! 
 
Laura KeetonLaura Keeton
When I changed it from (b) to (a), the coverage went down.  However, it gave me a direction on what I need to do and I got the coverage to 100%.  Thanks!
VamsiVamsi
Perfect !!