You need to sign in to do that
Don't have an account?
onionbagle
Opportunity Trigger
Hi All,
This is my first attempt at an apex trigger so please bear with me. I am trying to write a trigger that will update other opportunity records. The logic is as follows.
Any Opportunity is updated.
Take EVAL_serial_num__c from updated record and search all exsisting opportunity records for matching serial numbers
If match then update the matching opportunity's field EVAL_Stage__c = 'Returned';
I have the following code which isn't throwing any errors but at the same time it isn't updating opportunities with matching serial number fields.
Code:
Any help will be appreciated.
Thanks
This is my first attempt at an apex trigger so please bear with me. I am trying to write a trigger that will update other opportunity records. The logic is as follows.
Any Opportunity is updated.
Take EVAL_serial_num__c from updated record and search all exsisting opportunity records for matching serial numbers
If match then update the matching opportunity's field EVAL_Stage__c = 'Returned';
I have the following code which isn't throwing any errors but at the same time it isn't updating opportunities with matching serial number fields.
Code:
trigger evaluationUpdate on Opportunity (after update) { for (Opportunity opp : Trigger.new) { String serialNum; serialNum = opp.EVAL_serial_num__c; Opportunity[] Opps = [select ID, EVAL_Stage__c from Opportunity where EVAL_serial_num__c = serialNum]; for (Opportunity o : Opps) { if(EVAL_Stage__c != 'Returned'){ o.update(EVAL_Stage__c = 'Returned'); o.EVAL_Stage__c = 'Returned'; } } } }
Any help will be appreciated.
Thanks
Give this version a try:
Code:
Structuring updates this way is a start, but you'll soon hit the governor limits. To delay hitting the limits, it is necessary to pull the select and update statements outside of the for loops.
Hope this helps, JoeK
Code:
The version by JoeK still has the queries inside the for loops which will cause your trigger to break anytime it processes more than 20 records.
Message Edited by TehNrd on 10-01-2007 03:43 PM
-Thanks again!