You need to sign in to do that
Don't have an account?
sudhIr Narayan
Trigger code coverage is 14%
Hi
I wrote a trigger on opportunity to update a custom field called discount program
For the above trigger I wrote a test class to get code coverage its showing only 14% Please suggest me how to get more code coverage please suggest me how to modify the code
Thanks
Sudhir
I wrote a trigger on opportunity to update a custom field called discount program
trigger NewDiscountProgramUpdate on Opportunity (After Insert, Before Update) { // ******** Trigger Created By Sudhir ************ // Loop through the incoming records list<opportunity> opp = new list<opportunity>(); for (Opportunity o : Trigger.new) { // Check for Deal Reg Not Null if ( o.FORCE_NSP__c == NULL && o.discount_program__c <> 'NSP' && o.Deal_Registration__c <> NULL ) { if ( o.Partner_Driven__c == 'Yes' && o.Partner_Led__c == 'No' && o.K_12__c == 'No' ) { o.discount_program__c = 'DEALREG/PI'; o.Abbv_Discount_Program__c = 'DR/PI'; } else if ( o.Partner_Driven__c == 'No' && o.Partner_Led__c == 'Yes' && o.K_12__c == 'No' ) { o.discount_program__c = 'DEALREG/PL'; o.Abbv_Discount_Program__c = 'DR/PL'; } else if ( o.Partner_Driven__c == 'Yes' && o.Partner_Led__c == 'Yes' && o.K_12__c == 'No' ) { o.discount_program__c = 'DEALREG/PI/PL'; o.Abbv_Discount_Program__c = 'DR/PI/PL'; } else if ( o.Partner_Driven__c == 'No' && o.Partner_Led__c == 'No' && o.K_12__c == 'Yes' ) { o.discount_program__c = 'DEALREG/K-12'; o.Abbv_Discount_Program__c = 'DR/K12'; } else if ( o.Partner_Driven__c == 'Yes' && o.Partner_Led__c == 'No' && o.K_12__c == 'Yes' ) { o.discount_program__c = 'DEALREG/PI/K-12'; o.Abbv_Discount_Program__c = 'DR/PI/K12'; } else if ( o.Partner_Driven__c == 'No' && o.Partner_Led__c == 'Yes' && o.K_12__c == 'Yes' ) { o.discount_program__c = 'DEALREG/PL/K-12'; o.Abbv_Discount_Program__c = 'DR/PL/K12'; } else if ( o.Partner_Driven__c == 'Yes' && o.Partner_Led__c == 'Yes' && o.K_12__c == 'Yes' ) { o.discount_program__c = 'DEALREG/PI/PL/K-12'; o.Abbv_Discount_Program__c = 'DR/PI/PL/K12'; } else { o.discount_program__c = 'DEALREG'; o.Abbv_Discount_Program__c = 'DR'; } } opp.add(o); } }
For the above trigger I wrote a test class to get code coverage its showing only 14% Please suggest me how to get more code coverage please suggest me how to modify the code
@isTest(SeeAllData = true) private class Test_Insert_Opp { public static testmethod void testopp() { test.startTest(); Opportunity opp = new Opportunity (Name='Test Opp', closeDate=system.today(),recordtypeId = '0123000000094yH', accountId = '0013000000DULXG',ForecastCategoryName = 'Pipeline',Government_Contract__c = 'None', StageName ='Renewal',Type='Existing Customer',Pricebook2Id='01s60000000AKxZAAW', Primary_Competitor__c = 'No Competitor', LeadSource='Renewal', ownerid='00560000001vfE5AAI',Channel_Source__c='Distributor',Discount_Program__c='NSP' ); insert opp; test.stopTest(); } }
Thanks
Sudhir
create additional opportunity records which satisfy the if- else condition and insert the record:
Important :
If this is what you were looking for then please mark it as a "SOLUTION" or You can Click on the "Like" Button if this was beneficial for you.