• Pashman
  • NEWBIE
  • 0 Points
  • Member since 2017


  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 2
    Replies
I'm new to Triggers and are trying to put in a trigger that updates all related child records on Opportunity. I have a custom object with a Master-Detail to the Opportunity and I'm trying to accomplish the following in a trigger:
 
Everytime a new record on the custom object is created I'd like it to uncheck a checkbox on all records for that Opportunity ID (and subsequently check that box for the newly created record but since the first part doesn't work I haven't tried to code this yet).
 
I also haven't put in the loop yet as since it won't even update a single record so far.
 
Here's my (bad) code:
 
trigger flag_fsc on Funnel_Scorecard__c (after update, after insert)
{
CustomObject__c[] fsc = trigger.new;
CustomObject__c[] fsc_update;
 
fsc_update[0] = [SELECT id, Most_Recent__c FROM Custom Object__c WHERE id = :fsc[0].opportunity__c] AND fsc[0].Most_Recent__c = TRUE;
 
fsc_update[0].Most_Recent__c = False;
  
update fsc_update[0];

}
 
And here's the error message:
 
Apex trigger flag_fsc caused an unexpected exception, contact your administrator: flag_fsc: execution of AfterUpdate caused by: System.ListException: List index out of bounds: 0: Trigger.flag_fsc: line 9, column 14
 
Any ideas anyone?
 
Thanks!