You need to sign in to do that
Don't have an account?

Apex code coverage is 50%. Please help.
Here is my code where I am updating one picklist field to another picklist field but I am only achieving 50% code coverage. Please help.
Apex trigger:
trigger BusinessSegment on Opportunity (before insert) {
for(Opportunity op: Trigger.new){
if(op.Solution_Offering__c=='Debt Financing'||op.Business_Application__c=='Equipment Finance' ){
op.Use_Type_Class__c='Financing/Capital Raising';
op.Use_Type__c='Equipment Finance';
} } }
Apex class:
@isTest private class testMyBusinessSegment { Public static testMethod void testTBusinessSegment () {
Opportunity opp = new Opportunity();
opp.name = 'Test - New Mapping';
opp.Type = 'Transaction - New';
opp.Region__c = 'Americas';
opp.Template__c='Blocks';
opp.StageName = 'Propose';
opp.dlDealType__c = 'Micro Deal';
insert opp;
} }
Hi Abhishek,
try the below code.
@isTest private class testMyBusinessSegment { Public static testMethod void testTBusinessSegment () {
Opportunity opp = new Opportunity();
opp.name = 'Test - New Mapping';
opp.Type = 'Transaction - New';
opp.Region__c = 'Americas';
opp.Template__c='Blocks';
opp.StageName = 'Propose';
opp.dlDealType__c = 'Micro Deal';
opp.Solution_Offering__c='Debt Financing';
opp.Business_Application__c='Equipment Finance';
insert opp;
} }
All Answers
Hi Abhishek,
try the below code.
@isTest private class testMyBusinessSegment { Public static testMethod void testTBusinessSegment () {
Opportunity opp = new Opportunity();
opp.name = 'Test - New Mapping';
opp.Type = 'Transaction - New';
opp.Region__c = 'Americas';
opp.Template__c='Blocks';
opp.StageName = 'Propose';
opp.dlDealType__c = 'Micro Deal';
opp.Solution_Offering__c='Debt Financing';
opp.Business_Application__c='Equipment Finance';
insert opp;
} }
Thanks it worked.
Please help. Again I extend the trigger. But my coverage came down to 36%. Please help.
trigger BusinessSegment on Opportunity (before insert) {
for(Opportunity op: Trigger.new){
if(op.Solution_Offering__c=='Audit/Compliance'&& (op.Business_Application__c=='Audit Management' ||op.Business_Application__c=='Financial Audit Management'||op.Business_Application__c=='Regulatory Audit Management') ){
op.Use_Type_Class__c='Audit/Compliance' ;
op.Use_Type__c='Financial Audit';
op.Solution__c='IL Exchange' ;
}
}
{
for(Opportunity opp: Trigger.new){
if(opp.Solution_Offering__c=='Audit/Compliance'&& opp.Business_Application__c=='Compliance Management' ){
opp.Use_Type_Class__c='Audit/Compliance' ;
opp.Use_Type__c='Other Audit/Compliance';
opp.Solution__c='Compliance Link';
}
}
}
{
for(Opportunity opp1: Trigger.new){
if(opp1.Solution_Offering__c=='Fund Management'&&
(opp1.Business_Application__c=='Investor Reporting'
|| opp1.Business_Application__c=='Portfolio Company Reporting'
|| opp1.Business_Application__c=='AI Fundraising' )){
opp1.Use_Type_Class__c='Financing/Capital Financing' ;
opp1.Use_Type__c='AI Fundraising';
opp1.Solution__c='IL Exchange';
}
}
}
{
for(Opportunity opp2: Trigger.new){
if(opp2.Business_Application__c=='None' ){
opp2.Use_Type_Class__c='General' ;
opp2.Use_Type__c='Other (Specify in Description box)';
opp2.Solution__c='IL Exchange';
}
}
}
{
for(Opportunity opp3: Trigger.new){
if(opp3.Solution_Offering__c=='Corporate Services'&&
(opp3.Business_Application__c=='Contract Management'
|| opp3.Business_Application__c=='Vendor Management'
|| opp3.Business_Application__c=='Investor Reporting'
|| opp3.Business_Application__c=='Regulatory Reporting') ){
opp3.Use_Type_Class__c='General' ;
opp3.Use_Type__c='Contract Management';
opp3.Solution__c='IL Exchange';
}
}
}
{
for(Opportunity opp4: Trigger.new){
if(opp4.Solution_Offering__c=='Strategic Transactions'&&
(opp4.Business_Application__c=='Financing/Capital Raising'
|| opp4.Business_Application__c=='IPO'
|| opp4.Business_Application__c=='JV/Alliance Management'
|| opp4.Business_Application__c=='Acquisition Mgmt (Buy-side)'
|| opp4.Business_Application__c=='Bankruptcy/Restructuring' ) ){
opp4.Use_Type_Class__c='Financing/Capital Financing' ;
opp4.Use_Type__c='IPO';
opp4.Solution__c='IL Exchange';
}
}
}
{
for(Opportunity opp5: Trigger.new){
if(opp5.Solution_Offering__c=='Strategic Transactions'&& opp5.Business_Application__c=='Licensing' ){
opp5.Use_Type_Class__c='Licensing & Strategic Alliances' ;
opp5.Use_Type__c='Licensing';
opp5.Solution__c='Compliance Link';
}
}
}
}
Apex Class:
@isTest
private class testMyBusinessSegment {
Public static testMethod void testTBusinessSegment ()
{
Opportunity opp = new Opportunity();
opp.name = 'Test - New Mapping';
opp.Type = 'Transaction - New';
opp.Region__c = 'Americas';
opp.Template__c='Blocks';
opp.StageName = 'Propose';
opp.dlDealType__c = 'Micro Deal';
opp.Solution_Offering__c= 'Audit/Compliance';
opp.Business_Application__c= 'Audit Management';
insert opp;
}
{
Opportunity oppp = new Opportunity();
oppp.name = 'Test - Trigger 1';
oppp.Type = 'Transaction - New';
oppp.Region__c = 'Americas';
oppp.Template__c='Blocks';
oppp.StageName = 'Propose';
oppp.dlDealType__c = 'Small Deal';
oppp.Solution_Offering__c= 'Audit/Compliance';
oppp.Business_Application__c= 'Compliance Management';
insert oppp;
}
{
Opportunity oppp1 = new Opportunity();
oppp1.name = 'Test - Trigger 21';
oppp1.Type = 'Transaction - New';
oppp1.Region__c = 'Americas';
oppp1.Template__c='Blocks';
oppp1.StageName = 'Propose';
oppp1.dlDealType__c = 'Small Deal';
oppp1.Solution_Offering__c= 'Fund Management';
oppp1.Business_Application__c= 'AI Fundraising';
insert oppp1;
}
}