You need to sign in to do that
Don't have an account?
Michael Hedrick 2
Apex test class for oldmap
Hello
I am having trouble increading my COde coverage for my Trigger with my Test Class.
I have added the trigger below. The trigger created a new record when a field(Early_Buy_PY_Total) on the original object is update and the field Record_Processed__c = false. A workflow updates this field to ensure it does not get processes more than once. Coverage is at a dismall 26% but I am guessing that is because the Test class is not triggering the Apex Trigger. Any suggestions would be greatl;y appreciated.
Thanks
M
I am having trouble increading my COde coverage for my Trigger with my Test Class.
@isTest (SeeAllData = false) public class TestNewEarlyBuySalesProgram { @isTest public static void myTestClass() { Account a = new Account(); a.Name= 'Test SP Account'; a.Type= 'Dealer / Distributor'; a.Partner_Type__c = 'Dealer'; a.Tier__c = 'Stocking Dealer'; a.Status__c = 'Active'; a.RecordTypeId = '012j0000000cfvw'; insert a; Sales_Program__c sp = new Sales_Program__c(); sp.Name = 'TestSP'; sp.Record_Processed__c = False; sp.JDE_Number__c = '11111'; sp.Account__c = a.id; sp.Current_SBF_Year__c='2016'; sp.sales_Program_Type__c = 'SBF'; sp.External_Id__c = '2016_11111'; sp.Trex_Brand_Exclusive_Percentage__c= 1.0; sp.Trex_1_Competitive_Brand_Percentage__c = 2.0; sp.Early_Buy_PY_Total__c=0; sp.Trex_Exclusive__c = True; sp.Trex_1_Competitive_Brand__c = False; insert sp; sp.Early_Buy_PY_Total__c=3456874; sp.Record_Processed__c = True; update sp; test.startTest(); // sp.Early_Buy_PY_Total__c=3456874; // sp.Record_Processed__c = True; // update sp; Sales_Program__c sp1 = new Sales_Program__c(); sp1.Name = 'TestSP1'; sp1.Record_Processed__c = false; sp1.JDE_Number__c = '11111'; sp1.Account__c = a.id; sp1.Current_SBF_Year__c='2017'; sp1.sales_Program_Type__c = 'SBF'; sp1.External_Id__c = '2017_11111'; sp1.Trex_Brand_Exclusive_Percentage__c= 1.0; sp1.Trex_1_Competitive_Brand_Percentage__c = 2.0; sp1.Prior_Year_Indirect_Sales__c = 3456874; sp1.Trex_Exclusive__c = True; sp1.Trex_1_Competitive_Brand__c = False; // update sp1; // test.startTest(); insert sp1 ; test.stopTest(); } }
I have added the trigger below. The trigger created a new record when a field(Early_Buy_PY_Total) on the original object is update and the field Record_Processed__c = false. A workflow updates this field to ensure it does not get processes more than once. Coverage is at a dismall 26% but I am guessing that is because the Test class is not triggering the Apex Trigger. Any suggestions would be greatl;y appreciated.
Thanks
M
try below code And let us know if this will help you
All Answers
Since the trigger is to create a new record after the existing record is updated to fulfill a certain criteria, the test should be run on the update action instead as below.
test.startTest();
sp.Early_Buy_PY_Total__c=3456874;
sp.Record_Processed__c = True;
update sp;
test.stopTest();
The test data creation of SP1 is not necessary as the creation of SP1 is what you're expecting from the trigger to perform and to be tested.
Thanks,
ZX
If this helps, please marks as best answer. :)
Thanks for your help and time...
try below code And let us know if this will help you