-
ChatterFeed
-
0Best Answers
-
0Likes Received
-
0Likes Given
-
2Questions
-
1Replies
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);
}
}
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);
}
}
- Laura Keeton
- July 15, 2019
- Like
- 0
Obtain Account ID using ApexPages getparameters
I'm a newbie to Salesforce and Apex. I have a requirement to create a dynamic banner for Account pages based on criteria from another object where the options are entered by the user. So I'm adding a new visualforce page (which will be the banner) to the Account object. I'm can't seem to retrieve the current account ID from the account page.
Visualforce:
<apex:page standardcontroller="Account" extensions="clsPartnerBanner">
<script type="text/javascript" src="/js/functions.js"></script>
<script src="/soap/ajax/11.1/connection.js"></script>
<style>
.banner
{
text-align:center;
font-weight:bold;
font-size:150%;
padding:17px;
width:80%;
height:80x;
}
</style>
<apex:repeat value="{!lstPB}" var="pb" >
<apex:repeat value="{!acct}" var="a" >
<div render="!if(!a.Id == !pb.Organization__c, true, false)" style="background-color : {!pb.Banner_Background__c};" class="banner">
<apex:outputPanel >
<apex:outputText value="{!a.Industry}"></apex:outputText><br/>
<apex:outputText value="{!a.Phone}"></apex:outputText><br/>
<apex:outputText value="{!pb.Message__c}"></apex:outputText><br/>
<apex:outputText value="{!pb.Contact_Email__c}"></apex:outputText><br/>
<apex:outputText value="{!pb.Contact_Phone__c}"></apex:outputText>
<apex:outputText value="{!a.Id}"></apex:outputText>
</apex:outputPanel>
</div>
</apex:repeat>
</apex:repeat>
</apex:page>
Apex:
<apex:page standardcontroller="Account" extensions="clsPartnerBanner">
<script type="text/javascript" src="/js/functions.js"></script>
<script src="/soap/ajax/11.1/connection.js"></script>
<style>
.banner
{
text-align:center;
font-weight:bold;
font-size:150%;
padding:17px;
width:80%;
height:80x;
}
</style>
<apex:repeat value="{!lstPB}" var="pb" >
<apex:repeat value="{!acct}" var="a" >
<div render="!if(!a.Id == !pb.Organization__c, true, false)" style="background-color : {!pb.Banner_Background__c};" class="banner">
<apex:outputPanel >
<apex:outputText value="{!a.Industry}"></apex:outputText><br/>
<apex:outputText value="{!a.Phone}"></apex:outputText><br/>
<apex:outputText value="{!pb.Message__c}"></apex:outputText><br/>
<apex:outputText value="{!pb.Contact_Email__c}"></apex:outputText><br/>
<apex:outputText value="{!pb.Contact_Phone__c}"></apex:outputText>
<apex:outputText value="{!a.Id}"></apex:outputText>
</apex:outputPanel>
</div>
</apex:repeat>
</apex:repeat>
</apex:page>
Visualforce:
<apex:page standardcontroller="Account" extensions="clsPartnerBanner">
<script type="text/javascript" src="/js/functions.js"></script>
<script src="/soap/ajax/11.1/connection.js"></script>
<style>
.banner
{
text-align:center;
font-weight:bold;
font-size:150%;
padding:17px;
width:80%;
height:80x;
}
</style>
<apex:repeat value="{!lstPB}" var="pb" >
<apex:repeat value="{!acct}" var="a" >
<div render="!if(!a.Id == !pb.Organization__c, true, false)" style="background-color : {!pb.Banner_Background__c};" class="banner">
<apex:outputPanel >
<apex:outputText value="{!a.Industry}"></apex:outputText><br/>
<apex:outputText value="{!a.Phone}"></apex:outputText><br/>
<apex:outputText value="{!pb.Message__c}"></apex:outputText><br/>
<apex:outputText value="{!pb.Contact_Email__c}"></apex:outputText><br/>
<apex:outputText value="{!pb.Contact_Phone__c}"></apex:outputText>
<apex:outputText value="{!a.Id}"></apex:outputText>
</apex:outputPanel>
</div>
</apex:repeat>
</apex:repeat>
</apex:page>
Apex:
<apex:page standardcontroller="Account" extensions="clsPartnerBanner">
<script type="text/javascript" src="/js/functions.js"></script>
<script src="/soap/ajax/11.1/connection.js"></script>
<style>
.banner
{
text-align:center;
font-weight:bold;
font-size:150%;
padding:17px;
width:80%;
height:80x;
}
</style>
<apex:repeat value="{!lstPB}" var="pb" >
<apex:repeat value="{!acct}" var="a" >
<div render="!if(!a.Id == !pb.Organization__c, true, false)" style="background-color : {!pb.Banner_Background__c};" class="banner">
<apex:outputPanel >
<apex:outputText value="{!a.Industry}"></apex:outputText><br/>
<apex:outputText value="{!a.Phone}"></apex:outputText><br/>
<apex:outputText value="{!pb.Message__c}"></apex:outputText><br/>
<apex:outputText value="{!pb.Contact_Email__c}"></apex:outputText><br/>
<apex:outputText value="{!pb.Contact_Phone__c}"></apex:outputText>
<apex:outputText value="{!a.Id}"></apex:outputText>
</apex:outputPanel>
</div>
</apex:repeat>
</apex:repeat>
</apex:page>
- Laura Keeton
- June 11, 2019
- Like
- 0
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);
}
}
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);
}
}
- Laura Keeton
- July 15, 2019
- Like
- 0