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
Danielle Rosen 8Danielle Rosen 8 

deploying trigger

Hello, 

I have a trigger that is successful in the sandbox, but when I try to deploy, I receive the error that there is a "code coverage failure." I'm very new to Apex/triggers and would really appreciate some guidance. I'm reading that I might be missing a testing step, but not sure how to execute on this. Thanks in advance for your help!

trigger UpdateopportunityfromlineBW on OpportunityLineItem (after insert,after update) {
    map<id,Decimal> mapcost= new map<id,Decimal>();
    OpportunityLineItem oldoli = new OpportunityLineItem();
    for(OpportunityLineItem oli:Trigger.new){
        if(Trigger.isupdate)
         oldoli= trigger.oldmap.get(oli.id);
        if(oli.Product2Id=='01t2E00000R6p18QAB' &&(Trigger.isinsert || (Trigger.isupdate && oli.unitprice!=oldoli.UnitPrice))) {
           mapcost.put(oli.OpportunityId, oli.UnitPrice); 
            system.debug('into it');
        }
       
    }
    
    if(mapcost.size()>0){
        List<Opportunity> opplist=[select id,BW_Fee__c  from opportunity where id in :mapcost.keySet()];
        List<Opportunity> opptobeupdate= new List<Opportunity>();
        
        for(opportunity opp:opplist){
            opp.BW_Fee__c=mapcost.get(opp.id);
            opptobeupdate.add(opp);
        }
        
        if(opptobeupdate.size()>0)
            update opptobeupdate;
    }
}
AnkaiahAnkaiah (Salesforce Developers) 
Hi Danielle,

refer the below link will help you to proceed further on your test class.

https://salesforce.stackexchange.com/questions/72883/how-to-create-opportunity-line-items-in-test-classes

Still facing issues, let me know will help you with code.

Thanks!!