• Danielle Rosen 8
  • NEWBIE
  • 20 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 11
    Replies
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;
    }
}
Hello,

I am completely new to Apex and triggers, and hoping someone can help with my first one. What I am trying to do is every time an opportunity line item is created, if it is a particular ProductId, I want it to populate a custom field on the parent opportunity. I'd like for it to do the same thing when the OLI sales price is updated, it should update the appropriate custom field. 

Any guidance here would be very appreciated as I am unsure how to get started. Thanks so much in advance!
Hi there, I'm seeing some solutions to my question, but they're not exactly what I'm looking for. I am trying to convert the entry on a currency field to a text formula field. The below formula gets me the closest to what I need, but it seems to eliminate decimal places. i.e. $1.00 changes to $1. Is it possible to retain the decimals without rounding? Thanks in advance!

"$"&
 TEXT( UnitPrice )
Hi there, I'm not sure what's wrong with my logic here:

AND ( ISPICKVAL(A_la_carte__c, "")
)
OR (
ISPICKVAL( Opportunity_Type__c, "Video Ad Server"),  
ISPICKVAL( Opportunity_Type__c, "VAD Renewal"),
ISPICKVAL( Opportunity_Type__c, "Amendment"),
) )

I'm trying to say, if the opportunity type selected is any of the above, and a value is not selected in the drop down 'A_la_carte__c' then show validation rule. I'm getting the synax error "Extra OR." Thanks in advance for your help.
Hello,

I am completely new to Apex and triggers, and hoping someone can help with my first one. What I am trying to do is every time an opportunity line item is created, if it is a particular ProductId, I want it to populate a custom field on the parent opportunity. I'd like for it to do the same thing when the OLI sales price is updated, it should update the appropriate custom field. 

Any guidance here would be very appreciated as I am unsure how to get started. Thanks so much in advance!
Hi there, I'm seeing some solutions to my question, but they're not exactly what I'm looking for. I am trying to convert the entry on a currency field to a text formula field. The below formula gets me the closest to what I need, but it seems to eliminate decimal places. i.e. $1.00 changes to $1. Is it possible to retain the decimals without rounding? Thanks in advance!

"$"&
 TEXT( UnitPrice )
Hi there, I'm not sure what's wrong with my logic here:

AND ( ISPICKVAL(A_la_carte__c, "")
)
OR (
ISPICKVAL( Opportunity_Type__c, "Video Ad Server"),  
ISPICKVAL( Opportunity_Type__c, "VAD Renewal"),
ISPICKVAL( Opportunity_Type__c, "Amendment"),
) )

I'm trying to say, if the opportunity type selected is any of the above, and a value is not selected in the drop down 'A_la_carte__c' then show validation rule. I'm getting the synax error "Extra OR." Thanks in advance for your help.