Study for the Salesforce Platform Developer Exam. Study with flashcards and multiple choice questions, each question has hints and explanations. Get ready for your exam!

Practice this question and more.


In order to execute code when a record is updated, which trigger event should be used?

  1. before insert

  2. after update

  3. before update

  4. after delete

The correct answer is: before update

To execute code when a record is updated, the appropriate trigger event is the one that allows access to both the old and new values of the record. The "before update" event occurs before any changes to the record are committed to the database, allowing developers to modify the record's field values or validate changes before they are saved. This is particularly useful for enforcing business rules or validating input. Choosing "before update" means that you can take action prior to the record being saved, ensuring that any necessary adjustments can be made without any reliance on performing operations after the change has already occurred. While "after update" is also related to updates, it is executed after the record has been modified in the database. This is typically used for operations that should happen as a consequence of an update, such as sending notifications or updating related records. However, it does not allow for modification of the record itself before the update is finalized, which is the key reason for opting for the "before update" trigger. The other events listed, such as "before insert" and "after delete," are not suitable for the requirement because they pertain to different actions (creating new records and handling record deletions, respectively) rather than updates.