5

Can I use an addError in an after insert trigger? And if so, is the created object deleted?

11

When you use the addError method in the after insert trigger, the record insertion is reverted back and you wont be able to find the same in the DB.

Actually the after insert trigger fires just before the commit, and any record which is tagged by addError is not commited to DB

2
  • 6
    Also worth noting that when using addError in "after insert" any autonumber fields do not get reverted - so this results in gaps in the sequence of numbers. Mar 1 '13 at 16:05
  • The documentation mentions that using addError in the before insert/update causes the error to be displayed on the UI. Is that the case for after triggers as well?
    – Vid L
    Jul 20 '16 at 14:46
0

You can definitely use addError() on after insert or update and the error messege will be displayed. Transaction will be rolled back.

1
  • Welcome to SF.SE Pavlo. You may not realize it but you've added a new answer to a 6 yr old question with a correct accepted answer. You'll notice that your answer has been downvoted, most likely because it's incorrect. The transaction will not be rolled back. You may want to double check documentation before answering questions in the future. It's always good to be able to cite documentation as part of your answer. See the Help center for more on Answering.
    – crmprogdev
    Mar 30 '19 at 18:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.