You need to sign in to do that
Don't have an account?
Danielle 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;
}
}
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;
}
}
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!!