Why a record cannot be updated in after trigger?

206    Asked by DavidEdmunds in Salesforce , Asked on Apr 19, 2023

I know after triggers cannot update the same record. But I would like to know why. I know the record is committed into the database. So the record is read only. But why is the record read only?

Answered by Coleman Garvin

Apex triggers allow you to choose to run code at specific points in a database operation where the semantics are well defined:

before trigger: before the database has been updated after trigger: after the database has been updated So by design, if the platform allowed modification of the record in an after trigger, the record cannot be updated and change would not be persisted and thrown away. You can choose whether to use a before or after trigger.

(The design probably comes from the underlying Oracle database.)


Your Answer

Interviews

Parent Categories