I have an afterInsert trigger on Events. When the Script is finished, I would like to delete the event. I keep getting this error message.
DML statement cannot operate on Trigger.new or Trigger.old
If I cannot do this within Trigger.new, what is the best way to do this? If SOQL is involved, what field am I looking for? event.ID?
Best Answer
You cannot operate on records from the trigger context. You can take those same records and perform
DML
on them if you simply change the reference.However, in this case you can take a simpler approach and call
Database.delete
on aList<Id>
.