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
cathy369cathy369 

Trigger Before issue

while this trigger works on individual records, bulk processing processes all new records instead of the intended records... i've tried several different ways to change this, but am failing miserably... any help would be greatly appreciated... i know the issue is the second "for (Opportunity o: System.Trigger.new)"... but I don't know what the format should be...

 

anyways, thanks for any help!

 

Trigger mfgPriceQuote on Opportunity (before insert, before update) {

// only update 'Print & Mfg Quote' records

  Id recId = Schema.SObjectType.Opportunity.getRecordTypeInfosByName().get('Print & Mfg Quote').getRecordTypeId();
  Id recId2 = Schema.SObjectType.Opportunity.getRecordTypeInfosByName().get('Print Quote').getRecordTypeId();
  system.debug('redId: ' + recId + '    recId2:  ' + recId2);

//set up maps for mfg run charges... 

  Map<Id, Opportunity> oppQuotes = new Map<Id,Opportunity>();
  
  for (Opportunity opp: System.Trigger.new){
     if (opp.RecordTypeId == recId || opp.RecordTypeId == recId2){
         if (opp.Stock_Source__c != null) {
            if (opp.Number_Out__c == null || opp.Number_Out__c == 0){
               opp.addError(' Number Out must be greater than Zero for Manufacturing Quote - Please ReEnter');
            }else{
               if (opp.StageName.contains('Lost')){
                  system.debug('*** in should be Lost: ' + opp.StageName);
                  continue;
               }else{
                  oppQuotes.put(opp.id,opp);
               }
            }
        }else{
           opp.Mfg_Run_Price_1__c = 0.00;
           opp.Mfg_Size_Penalty_1__c = 0.00;
           opp.Other_Charges_1__c = 0.00;
           opp.Tinting_Charges_1__c = 0.00;
           opp.Mfg_Stock_Price_1__c = 0.00; 
        }
     }
  }
  
  if (oppQuotes.size() > 0){
  
     List<Mfg_Run_Charges__c> mrcRC = new List<Mfg_Run_Charges__c>
        ([SELECT Process_Code__c,
               X10_Reg__c,X10_Spcl_Win__c,X10_Std_Win__c,Double_Window__c,Max_Qty__c,Min_Qty__c,
               Non_10_Reg__c,Non_10_Spcl_Win__c,Non_10_Std_Win__c,Size_Penalty_Announcement__c,Size_Penalty_Announcement_M__c,
               Size_Penalty_Large__c,Size_Penalty_Small__c,Special_Window__c,Furnished_Penalty__c,Furnished_Penalty_PrePrin__c,
               Per_M_Charge__c, X14_and_Smaller_M_charge__c,Punch_Patch_Setup__c, Punch_Patch_M__c, Setup_Charge__c,
               Tint_9_and_Smaller__c, Tint_10_and_Larger__c, Miscellaneous_Charge__c
          FROM  Mfg_Run_Charges__c]);

     Map<Id,Envelope_Die__c> env = new Map<Id,Envelope_Die__c>();
  
     for(Envelope_Die__c ed : [SELECT id, X10_Commercial_Flap__c,X14_and_Smaller__c,
                                      X9_and_Smaller__c,Commercial_Size__c,Name,OE_214__c,
                                      OE_57__c,OS_658__c,OS_34__c,OS_534__c,Smaller_than_614__c
                               FROM Envelope_Die__c]){ 
        env.put(ed.id,ed);
     }
     
//****  I KNOW THIS IS MY ISSUE, BUT DON'T KNOW HOW TO FORMAT PROPERLY
     for (Opportunity o: System.Trigger.new){
        boolean mfgEnvYes = false;
        if (o.Envelope_Die_New__c != null){
            mfgEnvYes = true;
        }
        o.Mfg_Run_Price_1__c = 0.00;
        o.Mfg_Size_Penalty_1__c = 0.00;
        o.Other_Charges_1__c = 0.00;
        o.Tinting_Charges_1__c = 0.00;
        o.Mfg_Stock_Price_1__c = 0.00;  
.
.
.
}

 

Best Answer chosen by Admin (Salesforce Developers) 
Marko LamotMarko Lamot

yes, as you have now, the second "for (Opportunity o:trigger.new)" goes through all records that are 'triggered'.

In that loop you never check whether opportunity is actually in oppQuotes list

 

this would be the shortest solution to your problem 

for (Opportunity o: System.Trigger.new){

//check if opportunity is in
oppQuotes
if (oppQuotes.containsKey(o.id))
 {
boolean mfgEnvYes = false;
if (o.Envelope_Die_New__c != null){
mfgEnvYes = true;
}
o.Mfg_Run_Price_1__c = 0.00;
o.Mfg_Size_Penalty_1__c = 0.00;
o.Other_Charges_1__c = 0.00;
o.Tinting_Charges_1__c = 0.00;
o.Mfg_Stock_Price_1__c = 0.00;

.....
}
}

All Answers

Marko LamotMarko Lamot

post whole trigger code

cathy369cathy369
Trigger mfgPriceQuote on Opportunity (before insert, before update) {

// only update 'Print & Mfg Quote' records

  Id recId = Schema.SObjectType.Opportunity.getRecordTypeInfosByName().get('Print & Mfg Quote').getRecordTypeId();
  Id recId2 = Schema.SObjectType.Opportunity.getRecordTypeInfosByName().get('Print Quote').getRecordTypeId();
  system.debug('redId: ' + recId + '    recId2:  ' + recId2);

  Map<Id, Opportunity> oppQuotes = new Map<Id,Opportunity>();
  
  for (Opportunity opp: System.Trigger.new){
     if (opp.RecordTypeId == recId || opp.RecordTypeId == recId2){
         if (opp.Stock_Source__c != null) {
            if (opp.Number_Out__c == null || opp.Number_Out__c == 0){
               opp.addError(' Number Out must be greater than Zero for Manufacturing Quote - Please ReEnter');
            }else{
               if (opp.StageName.contains('Lost')){
                  system.debug('*** in should be Lost: ' + opp.StageName);
                  continue;
               }else{
                  oppQuotes.put(opp.id,opp);
               }
            }
        }else{
           opp.Mfg_Run_Price_1__c = 0.00;
           opp.Mfg_Size_Penalty_1__c = 0.00;
           opp.Other_Charges_1__c = 0.00;
           opp.Tinting_Charges_1__c = 0.00;
           opp.Mfg_Stock_Price_1__c = 0.00;  
        
           opp.Mfg_Run_Price_2__c = 0.00;
           opp.Mfg_Size_Penalty_2__c = 0.00;
           opp.Other_Charges_2__c = 0.00;
           opp.Tinting_Charges_2__c = 0.00;
           opp.Mfg_Stock_Price_2__c = 0.00;
          
        }
     }
  }
  
  system.debug('oppQuotes size: ' + oppQuotes.size());
  
  if (oppQuotes.size() > 0){
  
     List<Mfg_Run_Charges__c> mrcRC = new List<Mfg_Run_Charges__c>
        ([SELECT Process_Code__c,
               X10_Reg__c,X10_Spcl_Win__c,X10_Std_Win__c,Double_Window__c,Max_Qty__c,Min_Qty__c,
               Non_10_Reg__c,Non_10_Spcl_Win__c,Non_10_Std_Win__c,Size_Penalty_Announcement__c,Size_Penalty_Announcement_M__c,
               Size_Penalty_Large__c,Size_Penalty_Small__c,Special_Window__c,Furnished_Penalty__c,Furnished_Penalty_PrePrin__c,
               Per_M_Charge__c, X14_and_Smaller_M_charge__c,Punch_Patch_Setup__c, Punch_Patch_M__c, Setup_Charge__c,
               Tint_9_and_Smaller__c, Tint_10_and_Larger__c, Miscellaneous_Charge__c
          FROM  Mfg_Run_Charges__c]);

     Map<Id,Envelope_Die__c> env = new Map<Id,Envelope_Die__c>();
  
     for(Envelope_Die__c ed : [SELECT id, X10_Commercial_Flap__c,X14_and_Smaller__c,
                                      X9_and_Smaller__c,Commercial_Size__c,Name,OE_214__c,
                                      OE_57__c,OS_658__c,OS_34__c,OS_534__c,Smaller_than_614__c
                               FROM Envelope_Die__c]){ 
        env.put(ed.id,ed);
     }
     
// ** WRONG FORMAT ****
     for (Opportunity o: System.Trigger.new){
        boolean mfgEnvYes = false;
        if (o.Envelope_Die_New__c != null){
            mfgEnvYes = true;
        }
        o.Mfg_Run_Price_1__c = 0.00;
        o.Mfg_Size_Penalty_1__c = 0.00;
        o.Other_Charges_1__c = 0.00;
        o.Tinting_Charges_1__c = 0.00;
        o.Mfg_Stock_Price_1__c = 0.00;  
        
        o.Mfg_Run_Price_2__c = 0.00;
        o.Mfg_Size_Penalty_2__c = 0.00;
        o.Other_Charges_2__c = 0.00;
        o.Tinting_Charges_2__c = 0.00;
        o.Mfg_Stock_Price_2__c = 0.00;
          
        decimal clsrQty = 0;
        decimal clsrPerMQty = 0;
        decimal clsrQty2 = 0;
        decimal clsrPerMQty2 = 0;

        boolean clsr14AndSmaller = false;

        decimal wrkQty = 0;
        decimal wrkQty2 = 0;
        decimal wrkPerMQty = 0;
        decimal wrkPerMQty2 = 0;

        decimal stkPerMQty = 0;
        decimal stkPerMQty2 = 0; 

// minimum for closure, size penalties (except adj cut), etc qty is 1,000           
        decimal wrk2Qty = 0;
        decimal wrk2Qty2 = 0;
        decimal wrk2PerMQty = 0;
        decimal wrk2PerMQty2 = 0;

        Decimal closureCharge = 0.0;
        Decimal closureCharge2 = 0.0;
 
        Decimal envRunCharge = 0.0;
        Decimal envRunCharge2 = 0.0;
 
        Decimal SzPnltyEnvRunCharge = 0.0;
        Decimal SzPnltyEnvRunCharge2 = 0.0;
 
        Decimal otherCharge = 0.0;
        Decimal otherCharge2 = 0.0;
        
        Decimal SizePenaltyVar = 0.0;
        Decimal SizePenaltyVar2 = 0.0;
 
        Decimal StockCost = 0.0;
        Decimal StockCost2 = 0.0;
 
        Decimal SheetsNeeded = 0.0;
        Decimal SheetsNeeded2 = 0.0;
 
        Boolean StdWin = false;
        Boolean SpcWin = false;
        Boolean DblWin = false;
        Boolean NoWin = false;
        Boolean MOWinDie = false;
        
// get envelope info 
        String  mfgChk='  ';
        if (mfgEnvYes){
           system.debug('** o.env die: ' + o.Envelope_Die_New__c);
           system.debug('env size: ' + env.size());
           Envelope_Die__c e = env.get(o.Envelope_Die_New__c);
           mfgChk = e.Name.substring(0,2);
             
// if envelope die is a WEB (starts with WE), quoting is done long hand, so jump ship
           
           if (mfgChk == 'WE'){
              o.addError('Please use LONG HAND to quote WEB Envelopes');
              break;
           }
 
           system.debug(' im stayin....... ' + mfgChk);
           
// set variables for standard or special window charges
           if (o.Window_Die__c == null){
              NoWin = true;
           }else{
              if (o.Window_Die__c == 'MO Die' || o.Window_2_Die__c == 'MO Die'){
                 MOWinDie = true;
              }
              SpcWin = true;
              if (o.Window_Die_Sublist__c != null) {
                 Integer i = o.Window_Die_Sublist__c.length();
                 system.debug('** window check: ' + o.Window_Die_Sublist__c + ', ' + i);
                 if (i >=15){
                    string WinChk = o.Window_Die_Sublist__c.substring(0,15);
                    string WinChk2 = o.Window_Die_Sublist__c.substring(0,13);
                    system.debug('** standard win?: ' + WinChk + ', ' +  o.Window_1_Distance_from_Left__c + ', ' +o.Window_1_Distance_from_Bottom__c + ', ' + o.Window_2_Die__c);
                    if ((WinChk == '1 1/8  X  4 1/2' || WinChk2 == '1 1/8 X 4 1/2') && o.Window_1_Distance_from_Left__c == '7/8' && o.Window_1_Distance_from_Bottom__c == '1/2' && o.Window_2_Die__c == null){
                       StdWin = true;
                       SpcWin = false;
                    }
                 }
              }
              if (o.Window_2_Die__c != null){
                 DblWin = true;
              }
           }
           
// if manufacturing, set size for closure charges
           clsr14AndSmaller = e.X14_and_Smaller__c;
       
 //set minimum quantities; 2,500 for SO,LO,MO and 1,000 for all others (for run charges, not stock calculations)
           decimal [] wrkQuantities = new decimal[]{0,0};
           
           wrkQuantities=MfgMinQty.getMfgMinQty(o.Quantity_1__c,e.OE_214__c,e.OE_57__c,e.OS_658__c);   

           wrkQty = wrkQuantities[0];          
           wrkPerMQty = WrkQty/1000;
           wrk2Qty = wrkQuantities[1];
           wrk2PerMQty = wrk2Qty/1000;
           stkPerMQty = o.Quantity_1__c/1000;
           clsrQty = wrkQuantities[1];
           clsrPerMQty = clsrQty/1000;
           

           if (o.Quantity_2__c > 0){ 
              wrkQuantities=MfgMinQty.getMfgMinQty(o.Quantity_2__c,e.OE_214__c,e.OE_57__c,e.OS_658__c);              
              wrkQty2 = wrkQuantities[0];          
              wrkPerMQty2 = WrkQty2/1000;
              wrk2Qty2 = wrkQuantities[1];
              wrk2PerMQty2 = wrk2Qty2/1000;          
              stkPerMQty2 = o.Quantity_2__c/1000;
              clsrQty2 = wrkQuantities[1];
              clsrPerMQty2 = clsrQty2/1000;
           }

        }

// Closure charges

//set up closure quantities if not manufacturing        
        if (!mfgEnvYes){
           if (o.Quantity_1__c <= 1000){
              clsrQty = 1000;
           }else{
              clsrQty = O.Quantity_1__c;
           }
           clsrPerMQty = clsrQty/1000;
           
           if (o.Quantity_2__c > 0){
              if (o.Quantity_2__c <= 1000){
                 clsrQty2 = 1000;
              }else{
                 clsrQty2 = O.Quantity_2__c;
              }
              clsrPerMQty2 = clsrQty2/1000;
           }           
        }
// use size checkbox when not manufacturing as there is no envelope die                      
        if (!mfgEnvYes || mfgChk == 'ND'){
           if (o.Adhesive_Seal__c != null){
              clsr14AndSmaller = o.x511_or_Smaller__c;
           }
        }
        
        system.debug('closure:  seal, qty, perMqty: ' + o.Adhesive_Seal__c + ' ' + clsrQty + ' ' + clsrPerMQty + ' ' + clsr14AndSmaller);
        if (o.Adhesive_Seal__c != null) {
           closureCharge=closureCost.getClosureCost(clsrQty,
                                                 clsrPerMQty,
                                                 o.Adhesive_Seal__c,
                                                 clsr14AndSmaller,
                                                 mrcRC);
           if (clsrQty2 > 0){
              closureCharge2=closureCost.getClosureCost(clsrQty2,
                                                     clsrPerMQty2,
                                                     o.Adhesive_Seal__c,
                                                     clsr14AndSmaller,
                                                     mrcRC);
           }
        }                         
        system.debug('closure charge: ' + closureCharge);
                
        if (mfgEnvYes){
           decimal [] charges = new decimal[]{0,0}; 
           Envelope_Die__c eMfg = env.get(o.Envelope_Die_New__c);        
// RAs, WR, WRK run charges (not MO, LO or SO)- send in closure charge for size penalty
           if (!eMfg.OE_214__c && !eMfg.OE_57__C && !eMfg.OS_658__c){
              charges = WR_RACharge.getWR_RACharge(StdWin,SpcWin,DblWin,NoWin,
                                                eMfg, wrkPerMQty,wrkQty,closureCharge,o.Adhesive_Seal__c,
                                                mrcRC);        
              envRunCharge = charges[0];
              szPnltyEnvRunCharge = charges[1];
           
              if (wrkQty2 > 0){
                 charges = WR_RACharge.getWR_RACharge(StdWin,SpcWin,DblWin,NoWin,
                                                   eMfg, wrkPerMQty2,wrkQty2,closureCharge2,o.Adhesive_Seal__c,
                                                   mrcRC);        
                 envRunCharge2 = charges[0];
                 szPnltyEnvRunCharge2 = charges[1];
              }                               
                                        
              system.debug('GCPT EnvRunCharge: ' + envRunCharge);
              system.debug('GCPT SzPnltyEnvRunCharge: ' + SzPnltyEnvRunCharge );
           }          

// MO
           if ((eMfg.OE_57__c) || (eMfg.OS_658__c && !noWin)) {        
              charges = MOCharge.getMOCharge(stdWin,spcWin,dblWin,noWin,MOWinDie,
                                          wrkPerMQty,wrkQty,closureCharge,mrcRC);
           
              system.debug('MO qty 1: ' + wrkQty + ' ' + wrkPerMQty + ' ' + charges);
              envRunCharge = charges[0];
              o.Other_Charges_1__c = charges[1];
           
              if (wrkQty2 > 0){
                 charges = MOCharge.getMOCharge(stdWin,spcWin,dblWin,noWin,MOWinDie,
                                             wrkPerMQty2,wrkQty2,closureCharge2,mrcRC);
           
                 system.debug('MO qty 2: ' + wrkQty2 + ' ' + wrkPerMQty2 + ' ' + charges);
                 envRunCharge2 = charges[0];
                 o.Other_Charges_2__c = charges[1];
              }
           
//         Zero out closure charge - already included for MO
              closureCharge = 0;
              closureCharge2 = 0;
              closureCharge3 = 0;
              closureCharge4 = 0;

              system.debug('GCPT EnvRunCharge - MO: ' + envRunCharge);
              system.debug('GCPT otherCharge: ' + otherCharge );
           }     

// SO     
           if (eMfg.OE_214__c){ 
              envRunCharge = SOCharge.getSOCharge(stdWin,spcWin,dblWin,noWin,
                                               wrkPerMQty,wrkQty,mrcRC);
                                               
              if (wrkQty2 > 0){
                 envRunCharge2 = SOCharge.getSOCharge(stdWin,spcWin,dblWin,noWin,
                                                   wrkPerMQty2,wrkQty2,mrcRC);
              }

              system.debug('GCPT EnvRunCharge - SO: ' + envRunCharge);
           }
                
// LO     
           if (eMfg.OS_658__c && noWin){
              envRunCharge = LOCharge.getLOCharge(stdWin,spcWin,dblWin,noWin,
                                               wrkPerMQty,wrkQty,mrcRC);
           
              if (wrkQty2 > 0){
                 envRunCharge2 = LOCharge.getLOCharge(stdWin,spcWin,dblWin,noWin,
                                                   wrkPerMQty2,wrkQty2,mrcRC);
              }
                      
              system.debug('GCPT EnvRunCharge - LO: ' + envRunCharge);
           }       
// tinting charge
           decimal tintChg = 0;
           decimal tintChg2 = 0;
           decimal tintChg3 = 0;
           decimal tintChg4 = 0;
        
           if (o.Security_Tint__c != null){
              o.Tinting_Charges_1__c = tintCharge.getTintCharge(eMfg.X9_and_Smaller__c,o.Security_Tint__c,wrk2PerMQty,
                                                                wrk2Qty,mrcRC);
            
              if (wrkQty2 > 0){
                 o.Tinting_Charges_2__c = tintCharge.getTintCharge(eMfg.X9_and_Smaller__c,o.Security_Tint__c,wrk2PerMQty2,
                                                                   wrk2Qty2,mrcRC);
              } 

              system.debug('GCPT TintCharge: ' + tintChg);
           }
        }
// Run charge includes closure charge

        system.debug('where is the closure charge??? envRun, closeCharge: ' + envRunCharge + ' ' + closureCharge);

        o.Mfg_Run_Price_1__c = (envRunCharge + closureCharge).setScale(2, RoundingMode.HALF_UP);
        o.Mfg_Run_Price_2__c = (envRunCharge2 + closureCharge2).setScale(2, RoundingMode.HALF_UP);
        
                       
// Adjustable Die charge
        if (o.Adjustable_Die__c == true){
   
           system.debug('GCPT SizePenalty Charge(before): ' + szPnltyEnvRunCharge + ' ' + szPnltyEnvRunCharge2 + ' ' + szPnltyEnvRunCharge3);

           szPnltyEnvRunCharge = szPnltyEnvRunCharge + 
                                 adjDieCharge.getAdjDieCharge((o.Quantity_1__c/1000), o.Quantity_1__c, mrcRC);
              
           if (wrkQty2 > 0){
              szPnltyEnvRunCharge2 = szPnltyEnvRunCharge2 + 
                                     adjDieCharge.getAdjDieCharge((o.Quantity_2__c/1000), o.Quantity_2__c, mrcRC);
           }            
        }
       
// get stock charge
        string stockSourceChk=o.Stock_Source__c.substring(0,4);
        if (stockSourceChk == 'Furn'){
           boolean prePrint = true;
           if (o.Stock_Source__c=='Furnished - Blank'){
              prePrint = false;
           }
           system.debug('*** StockCharge.. using furnished, prePrint, wrkPerMQty,Qty_1' + prePrint + ' ' + wrkPerMQty + ' ' + o.Quantity_1__c);
           stockCost = StockCharge.getFurnCharge(prePrint,
                                                 wrk2PerMQty,
                                                 wrk2Qty,
                                                 mrcRC);
           if (o.Quantity_2__c > 0){
              stockCost2 = StockCharge.getFurnCharge(prePrint,
                                                    wrk2PerMQty2,
                                                    wrk2Qty2,
                                                    mrcRC);
           }
        }else{
           decimal stkPerMPrice = 0;
           if (stockSourceChk == 'Inve'){      
              Product2 prod = [SELECT Full_Carton__c 
                               FROM Product2
                               WHERE id = :o.Stock_Source_Product__c];
              stkPerMPrice = prod.Full_Carton__c;            
           }else{
              if (stockSourceChk == 'Boug'){
                 if (o.Markup_Bought__c > 0){
                    stkPerMPrice = o.Stock_Price_M_Bought__c * (1 + (o.Markup_Bought__c/100));
                 }else{     
                    stkPerMPrice = o.Stock_Price_M_Bought__c;
                 }
              }
           }
           
           system.debug('*** StockCharge.. using inventory,stkPerMPrice, qty_1,num out: ' + stkPerMprice + ' ' + o.Quantity_1__c + ' ' + o.Number_Out__c);
           stockCost = StockCharge.getStockCharge(stkPerMPrice,
                                                  o.Quantity_1__c,
                                                  o.Number_Out__c,
                                                  o.Adhesive_Seal__c);                                      
           if (o.Quantity_2__c > 0){
              stockCost2 = StockCharge.getStockCharge(stkPerMPrice,
                                                      o.Quantity_2__c,
                                                      o.Number_Out__c,
                                                      o.Adhesive_Seal__c);
           }

        }   
        system.debug('GCPT Stock Cost: ' + stockCost);
        o.Mfg_Size_Penalty_1__c = szPnltyEnvRunCharge.setScale(2, RoundingMode.HALF_UP);
        o.Mfg_Size_Penalty_2__c = szPnltyEnvRunCharge2.setScale(2, RoundingMode.HALF_UP);

        o.Mfg_Stock_Price_1__c = stockCost.setScale(2, RoundingMode.HALF_UP);
        o.Mfg_Stock_Price_2__c = stockCost2.setScale(2, RoundingMode.HALF_UP);
     }
  }
}

here it is... long and messy... thanks....

Marko LamotMarko Lamot

what exactly do you mean by

....bulk processing processes all new records instead of the intended records......

cathy369cathy369
the intent is to only process records of certain records types as well as
other criteria... i am putting those records in a map, oppQuotes...but as I
progress in my trigger, I am not just processing the records in my map, but
all new records...



while that works with just one record being processed, if there are multiple
records (I have some timed workflows that end up updating several
opportunity records at one time because of how Apex (SalesForce??) processes
them), EVERY record is through my trigger, not just the records meeting the
intended criteria...



hope this makes sense, because i know i'm not asking my question properly as
i am confused...



Cathy Halper

Desert Paper & Envelope Company, Inc.

505.884.0640



PRINT! The renewable way a responsible world communicates.
Marko LamotMarko Lamot

yes, as you have now, the second "for (Opportunity o:trigger.new)" goes through all records that are 'triggered'.

In that loop you never check whether opportunity is actually in oppQuotes list

 

this would be the shortest solution to your problem 

for (Opportunity o: System.Trigger.new){

//check if opportunity is in
oppQuotes
if (oppQuotes.containsKey(o.id))
 {
boolean mfgEnvYes = false;
if (o.Envelope_Die_New__c != null){
mfgEnvYes = true;
}
o.Mfg_Run_Price_1__c = 0.00;
o.Mfg_Size_Penalty_1__c = 0.00;
o.Other_Charges_1__c = 0.00;
o.Tinting_Charges_1__c = 0.00;
o.Mfg_Stock_Price_1__c = 0.00;

.....
}
}
This was selected as the best answer
Marko LamotMarko Lamot

btw:

as I was checking your code, please note that

 

 Product2 prod = [SELECT Full_Carton__c 
                               FROM Product2
                               WHERE id = :o.Stock_Source_Product__c];

 

might cause you "too many soql limits".  

I mean if there will be a case where larger "bulk" will occur with many situattion where above statement will execute, you will get   "too many soql limits" exeption.

 

I would put this out of for statement and put necessary product values in to map

cathy369cathy369
thank you soooo much. that's exactly what I was looking for. and you're
right, I need to take care of the below. while I haven't run into soql
limits on this yet, I'm sure there is the potential.



Product2 prod = [SELECT Full_Carton__c FROM Product2 WHERE id =
:o.Stock_Source_Product__c];



again, thank you for your help. I'm changing my trigger now, and beefing up
my testing.





Cathy Halper

Desert Paper & Envelope Company, Inc.

505.884.0640



PRINT! The renewable way a responsible world communicates.