You need to sign in to do that
Don't have an account?

Need help modifying a trigger
I need help modifying a trigger I wrote. The trigger is supposed to update the parent opportunity record everytime the child record, Media_Plan_History__c, is updated, which works correctly.
I need to add a condition to the trigger so that the opportunity is only updated if a checkbox called Active__c is set to True on the Media_Plan_History__c record. Where can I add this logic to the trigger? I can't quite figure it out.
Thanks!
Here's my trigger:
trigger OppOwnerSH on Media_Plan_History__c (after update) {
Media_Plan_History__c[] shs;
shs = Trigger.new;
set<Id> oppIds = new Set <ID>();
for (Media_Plan_History__c sh : shs) {
oppIds.add(sh.Opportunity__c);
Map<ID, Opportunity> oppsToUpdate = new Map<ID, Opportunity> (
[select Id, Media_Planner_2__c from Opportunity
where Id in :oppIds]);
List<Opportunity> oppUpd = new List<Opportunity>{};
for (Opportunity opp : oppsToUpdate.values()) {
opp.media_planner_2__c = sh.media_planner_2__c;
update opp;
oppUpd.add(opp);
}
if (oppUpd != null && !oppUpd.isEmpty())
Database.update(oppUpd);
}
}
Give this a whirl...
-Andy
All Answers
This is a guess. I'm new to Apex. Since this is my 3rd post....
Wrapping the code with something like
Give this a whirl...
-Andy
Thank you so much! That worked!