You need to sign in to do that
Don't have an account?
Can(t) delete original object using a DML operation on trigger after update?!?!?!
Hi,
According to Apex-Guide: Can delete original object using a DML operation on trigger after update; According to Test-Method: DML statment cannot operate on trigger.new or trigger.old
that was my previous message subject but it seems a bit to long ;)
So, why the apex-guide assert that you can delete the original object, when on the other hand I get an error in the test-log.
trigger RunMyJob on myJob__c (after update)
{
myJob__c mjn = new myJob__c();
insert mjn;
SOmyCreateBacklogs.createBack(trigger.new[0]);
myJob__c old = trigger.new[0];
delete old;
}
Does anyone knows what I'm doing wrong?
Thanks and best regards
Sascha
Message Edited by ne-rm-team on 12-05-2008 04:47 AM
I am not sure what you´re trying to do here, since the trigger.old will be gone from the database anyway after an update, no use to delete it? Also I suggest placing any logic in a trigger in a loop, instead of assuming 1 record with trigger.old/new[0].
Message Edited by Harmpie on 12-06-2008 06:57 AM
I didn't knew that I'm deleting the trigger.old. I thought I delete a variable named "old" wich contains the trigger.new[0] value. :smileywink:
1. When I was posting my problem I tried to stay focused on the essentials.
2. The Problem ist, that I want to delete the original object, wich fires the trigger but I can't. The language reference says I can, but the debug log is throwing an error out (you can see it in the subject).
3. I don't need a loop for picking up more than one record since I am totaly shure that there is always only one record, wich could fire the trigger.
I just whant to know if I did something wrong or if the apex reference contains a wrong statement.
Best regards
Sascha
Message Edited by ne-rm-team on 12-08-2008 12:47 AM