You need to sign in to do that
Don't have an account?
Can I avoid whole trigger rollback on unsuccessful insertion?
Hello,
Is there any way (a supported way or a tricky workaround) to make Salesforce not to rollback changes done in the trigger eventhough the insertion failed?
Sometimes I want to fail the insertion (addError on the sObject) but I want other changes done in the trigger to still happen.
For example:
trigger triggerName on Contact (before insert) { Contact newContact = Trigger.new[0]; Contact existingContact = [Select FirstName From Contact Where Id = 'someId']; existingContact.FirstName = newContact.FirstName; update existingContact; insert new Account(Name='newAccount'); newContact.addError('errorName'); }
In this case, when adding a contact, the update of exisitingContact and the insertion of newAccount will be rolled back...
I do want those changes to occur, eventhough I want the newContact not to be inserted.
Playning with opt_allOrNone didn't seem to have any effect.
Thanks in advance!
Itay
Hi,
Have you tried using 'try-catch-finally' block?
Put all your statments which you want to execute even after the exception in finally block.
Thanks for you response!
I tried both:
and:
Any other thoughts?
Thanks!
Itay