You need to sign in to do that
Don't have an account?
Bill5
Trigger update object before delete
According to the above link a before delete trigger "can update an original object using an update DML operation nd the updates are saved before the object is deleted, so if the object is undeleted, the updates become visible". However, the contents of the trigger.old collection are read-only and trigger.new is only available in insert and update triggers. Therefore how can a objects value be modified as part of the trigger before delete?
I would like to be able to chage the value of one of the fields on an object when it is deleted.
Thanks
Bill
Update by dml means that you would have to create a copy of the object from trigger.old, then execute the update call using that copy.
All Answers
Update by dml means that you would have to create a copy of the object from trigger.old, then execute the update call using that copy.
But if you create a copy and then update it, won't you have one object in the recycle bin (the one that was passed into the trigger) and a new one in the database? It sounds like the objective is to change the value on a field as it is on it's way the recycle bin.
Unfortunately, once something is in the recycle bin, you cannot modify it. For example, the following does not work, but I think it illustrates what you are trying to achieve:
Maybe you can build some sort of future method that is called from the trigger to 'undelete' these records, update them, and then delete them again?
I think the point is that until the trigger has completed the delete hasn't taken place.