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
Prentiss Jones 3Prentiss Jones 3 

How do I get test coverage on my trigger go up (65%)?

trigger RateCardPercentCalcInputsRCP on Line_Item__c (before insert,before update) {
    for(Line_Item__c li : trigger.new){
        Double rcpmod = 0;
        if(li.Blast__c == 'Hourly'){rcpmod+=2.5;}
        if(li.Blast__c == '1 Day'){rcpmod+=1.5;}
        //if(li.Day_Parting_Details__c != '' && (li.Blast__c == null || li.Blast__c == '2-7 Day')){rcpmod+=1;}
        if(li.Viewability__c && li.Rate_Card_Price__c>li.Sales_Price__c){rcpmod+=0.25;}
        if(li.Nielsen_OCR__c){rcpmod+=0.25;}
        if(li.BT_Deluxe__c){rcpmod+=0.50;}
        if(li.GoWatchIt_ViewNow__c){rcpmod+=0.50;}
        if(li.LDA__c&&li.Rate_Type__c=='CPM-GMV Xaxis'){rcpmod+=2;}
        if(li.LDA__c&&li.Rate_Type__c=='CPGMV Xaxis'){rcpmod+=2;}
        if(li.LDA__c&&li.Rate_Type__c=='CPM-GMV Group M'){rcpmod+=2;}
        if(li.LDA__c&&li.Rate_Type__c=='CPGMV Group M'){rcpmod+=2;}
        if(li.Retailigence__c){rcpmod+=0.35;}
        if(li.TMS__c && li.Total_Line_Price__c<100000){rcpmod+=0.75;}
        if(li.TMS__c && li.Total_Line_Price__c>=100000){rcpmod+=0.5;}
        /*if(li.Nielsen_Buyer_Insights_Modeling__c){rcpmod+=0.50;}
        if(li.Nielsen_Buyer_Insights_Custom__c){rcpmod+=0.90;}
        if(li.Nielsen_TV_Viewership_Modeling__c){rcpmod+=0.80;}
        if(li.Nielsen_TV_Viewership_Custom__c){rcpmod+=1.30;}
        if(li.NCS_Custom__c){rcpmod+=0.50;}
        if(li.LiveRamp_1st_Party__c){rcpmod-=1.50;}*/
        
        if(li.Primary_Channel__c == 'BT: Modeling' && li.Data_Provider__c=='Nielsen Buyer Insights' 
           && li.Rate_Type__c !='CPVC' && (!li.Product__c.contains('All S')||!li.Product__c.contains('Mobile'))){rcpmod+=0.5;}
        if(li.Primary_Channel__c == 'BT: Modeling' && li.Data_Provider__c=='Nielsen TV Viewership'
           && li.Rate_Type__c !='CPVC' && (!li.Product__c.contains('All S')||!li.Product__c.contains('Mobile'))){rcpmod+=0.8;}
        if(li.Primary_Channel__c == 'BT: Other/Custom' && li.Data_Provider__c=='Nielsen TV Viewership'
           && li.Rate_Type__c !='CPVC'&& (!li.Product__c.contains('All S')||!li.Product__c.contains('Mobile'))){rcpmod+=1.3;}
        if(li.Primary_Channel__c == 'BT: Other/Custom' && li.Data_Provider__c=='Nielsen Buyer Insights'
           && li.Rate_Type__c !='CPVC'&& (!li.Product__c.contains('All S')||!li.Product__c.contains('Mobile'))){rcpmod+=0.9;}
        if(li.Primary_Channel__c == 'BT: Other/Custom' && li.Data_Provider__c=='NCS Custom'
           && li.Rate_Type__c !='CPVC'&& (!li.Product__c.contains('All S')||!li.Product__c.contains('Mobile'))){rcpmod+=0.5;}
       
        //this section is universally applied
        if(li.Primary_Channel__c == 'BT: Other/Custom' && li.Data_Provider__c=='Crossix'
           && li.Rate_Type__c !='CPVC'){rcpmod+=0.75;}
        if(li.Primary_Channel__c == 'Handset: BT Other/Custom' && li.Data_Provider__c=='Crossix'
           && li.Rate_Type__c !='CPVC'){rcpmod+=0.75;}
        if(li.Primary_Channel__c == 'Mobile: BT Other/Custom' && li.Data_Provider__c=='Crossix'
           && li.Rate_Type__c !='CPVC'){rcpmod+=0.75;}
        if(li.Primary_Channel__c == 'Tablet: BT Other/Custom' && li.Data_Provider__c=='Crossix'
           && li.Rate_Type__c !='CPVC'){rcpmod+=0.75;}
        if(li.Primary_Channel__c == 'BT: Other/Custom' && li.Data_Provider__c=='LiveRamp 1st Party' 
           && li.Rate_Type__c !='CPVC'){rcpmod-=1.5;}
        if(li.Primary_Channel__c == 'BT: Other/Custom' && li.Data_Provider__c=='Quantcast' 
           && li.Rate_Type__c !='CPVC'){rcpmod-=1.5;}
        
        //below begins the upcharges for All Screen and Mobile. These are generally $1 more than non-All Screen, non-Mobile
        if(li.Primary_Channel__c == 'BT: Modeling' && li.Data_Provider__c=='Nielsen Buyer Insights' 
           && li.Rate_Type__c !='CPVC' && (li.Product__c.contains('All S')||li.Product__c.contains('Mobile'))){rcpmod+=1.5;}
        if(li.Primary_Channel__c == 'BT: Modeling' && li.Data_Provider__c=='Nielsen TV Viewership'
           && li.Rate_Type__c !='CPVC' && (li.Product__c.contains('All S')||li.Product__c.contains('Mobile'))){rcpmod+=1.8;}
        if(li.Primary_Channel__c == 'BT: Other/Custom' && li.Data_Provider__c=='Nielsen TV Viewership'
           && li.Rate_Type__c !='CPVC'&& (li.Product__c.contains('All S')||li.Product__c.contains('Mobile'))){rcpmod+=2.3;}
        if(li.Primary_Channel__c == 'BT: Other/Custom' && li.Data_Provider__c=='Nielsen Buyer Insights'
           && li.Rate_Type__c !='CPVC'&& (li.Product__c.contains('All S')||li.Product__c.contains('Mobile'))){rcpmod+=1.9;}
        if(li.Primary_Channel__c == 'BT: Other/Custom' && li.Data_Provider__c=='NCS Custom'
           && li.Rate_Type__c !='CPVC'&& (li.Product__c.contains('All S')||li.Product__c.contains('Mobile'))){rcpmod+=1.5;}
        
        //here are the upcharges for all data targeting that is CPVC


        if(li.Primary_Channel__c == 'BT: Modeling' && li.Data_Provider__c=='Nielsen Buyer Insights' 
           && li.Rate_Type__c =='CPVC' ){rcpmod+=4.25;}
        if(li.Primary_Channel__c == 'BT: Modeling' && li.Data_Provider__c=='Nielsen TV Viewership'
           && li.Rate_Type__c =='CPVC'){rcpmod+=4.25;}
        if(li.Primary_Channel__c == 'BT: Other/Custom' && li.Data_Provider__c=='Nielsen TV Viewership'
           && li.Rate_Type__c =='CPVC'){rcpmod+=4.25;}
        if(li.Primary_Channel__c == 'BT: Other/Custom' && li.Data_Provider__c=='Nielsen Buyer Insights'
           && li.Rate_Type__c =='CPVC'){rcpmod+=4.25;}
        if(li.Primary_Channel__c == 'BT: Other/Custom' && li.Data_Provider__c=='NCS Custom'
           && li.Rate_Type__c =='CPVC'){rcpmod+=4.25;}
       
        
        if(li.Retargeting__c && (li.Product__c.contains('All S') || li.Product__c.contains('Mobile'))){rcpmod+=1;}
        if(li.Sequential_Messaging__c && (li.Product__c.contains('All S') || li.Product__c.contains('Mobile'))){rcpmod+=1;}
        li.RCP_eCPM_Modifier__c=rcpmod;
    }

}
Subhani_SFDCSubhani_SFDC
Hi Prentiss Jones 3,

Can you post your exting test class code(which is not giving you atlease 65%) so that we will help you on how to increase the code coverage for your trigger.  Also, its always better to have more that 75 % of code coverage for any apex trigger/apex class 

Thanks, Subhani
Prentiss Jones 3Prentiss Jones 3
Should I pull the test classes from that sandbox or production? I'm new :(
Subhani_SFDCSubhani_SFDC
Hey,

You should have tried in google on how to create a test class for a trigger. 

Follow below steps to write a test class.

1.  Created the test record which your trying to perform an action thourgh your trigger.

2. Insert That record by using insert condition.

Basic Example:

The below code is realted to trigger for Account object


@isTest
public class TestAccount{
    static testMethod void insertNewAccount() {

    // call the required field for creating the record(I am taking )
     Account accObj = new Account(Name = 'Salesforce', BillingStreet = 'PO Box-1234',BillingCity = 'San Francisco',
                                        BillingState = 'California', BillingPostalCode  = '94101', BillingCountry = 'US',ShippingStreet = 'PO Box-1234',
                                        ShippingState = 'California', ShippingCity = 'San Francisco', ShippingPostalCode  = '94101', ShippingCountry = 'US');
    insert accObj;
    }
}

3. Also If you have to perform any update on the record, use the below criteria on the same

accObj.BillingStreet = 'PO Box-5678';

update accObj;

Try to undestand the above logic and start your own test class. If you stuck at anyplace,we are here to help our folks.

Also, refer the below link for more details.

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_qs_test.htm

Thanks, Subhani