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
amritamrit 

trigger is not updating

Hi,

 

I have a trigger in opportunity where im updating a currency fields (Proposed value, Actual value) when stage is 'Received'. 

Proposed value is an editable field.I can update the value in Proposed Value .But When i changed the Proposed value and update stage as 'Submitted' .The value is not getting updated. It s showing old value.

 

trigger CPIupdatevalues on Opportunity__c (before insert, before update) {


Set<Decimal> comp = new Set<Decimal>();
Set<Decimal> bid  = new Set<Decimal>();
Set<Decimal> inc  = new Set<Decimal>();
List<String> aud  = new List<String>();
List<String> stage = new List<String>();

List<String> market=new List<String>();
List<String> ratecard =new List<String>();

for(Opportunity__c l : trigger.new){

   if(l.Stage__c == 'Received'){
    if(l.Stage__c == 'Received'){
        stage.add(l.Stage__c);
    }
 
    if(l.Completes_Required__c != null){
        comp.add(l.Completes_Required__c);
       } 
    if(l.Bid_LOI_in_minutes__c != null){ 
        bid.add(l.Bid_LOI_in_minutes__c);
        }
    if(l.Incidence_Rate__c != null)
    {
        inc.add(l.Incidence_Rate__c);
     }
    if(l.Audience_B2B_B2C__c == 'B2B' || l.Audience_B2B_B2C__c == 'Gen Pop' &&l.Audience_B2B_B2C__c != 'Niche' )
    {    
        aud.add(l.Audience_B2B_B2C__c);
    }
    if(l.Market__c != null)
    {
        market.add(l.Market__c);
    }
   if(l.Rate_Card__c != null)
   {
     ratecard.add(l.Rate_Card__c);
   }
}
}

//If audience is B2B or Genpop
try{
if(aud.size()> 0){
    Map<Decimal, CPI__c> cpi1 = new Map<Decimal, CPI__c>();


    for(CPI__c obj1 : [SELECT Id, Bid_LOI_in_minutes__c,Actual_CPI__c,Actual_CPIchanged__c,Audience__c,Stage__c, Completes_Required__c,Name,Market__c FROM CPI__c WHERE    Bid_LOI_in_minutes__c IN :bid
                               AND  Completes_Required__c IN: comp AND Incidence_Rate__c IN:inc AND Audience__c IN:aud AND Name IN:ratecard AND Market__c IN:market AND Stage__c IN:stage ]){
        cpi1.put(obj1.Completes_Required__c , obj1);
        system.debug('CPI'+cpi1);
    }
    system.debug('@@@@@@@@@@@@@@<@@@cpi @@@@@@@@'+'cpi1 ');

    // We have all the reference data we need, last loop on the each Opportunity


    if(cpi1.size()>0){
        for(Opportunity__c l1 : trigger.new){
             
                l1.ActualValue__c = cpi1.get(l1.Completes_Required__c).Actual_CPIchanged__c;
                    if(l1.ProposedValue__c == 0 ){
                        l1.ProposedValue__c= cpi1.get(l1.Completes_Required__c).Actual_CPIchanged__c;//Updating Proposed value    
                    
                    }
            
        }  
        
    }
    else{
        for(Opportunity__c l1 : trigger.new){
            
                l1.Actual_CPI__c =0;
            
        }      
    }
    
}
}
catch(exception e){
}
}

 

Anyidea why it was not updating

crop1645crop1645

Hi amrit

 

I would focus your attention here:

    if(cpi1.size()>0){
        for(Opportunity__c l1 : trigger.new){
             
                l1.ActualValue__c = cpi1.get(l1.Completes_Required__c).Actual_CPIchanged__c;
                    if(l1.ProposedValue__c == 0 ){
                        l1.ProposedValue__c= cpi1.get(l1.Completes_Required__c).Actual_CPIchanged__c;//Updating Proposed value    
                    
                    }
            
        }  
        
    }

 You should see whether the lookup keys from ll.completes_required__c actually match anything built in the cpi1 map from the SOQL statement. You are comparing decimals from two different SObjects and they may have different precision and thus wouldn't match

amritamrit

Thanka for the reply.I got the solution .The proposed value was not updating only during stage Submitted.So i create  a field which has default value Submitted in CPI object and mapped in opportunity.Now it get updated once stage is submitted