You need to sign in to do that
Don't have an account?
cathy369
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; . . .
}
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
All Answers
post whole trigger code
here it is... long and messy... thanks....
what exactly do you mean by
....bulk processing processes all new records instead of the intended records......
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.
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
btw:
as I was checking your code, please note that
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
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.