Development questions

What is the difference between before triggers and after triggers?

DevelopmentEasyDeloitteAccentureWipro

Before triggers run before the record is saved to the database. Use them to validate or modify field values on the records in Trigger.new without an extra DML, since changes are saved automatically. Record Ids are not yet available on insert.

After triggers run after the record is saved (but not committed). Record Ids and system-populated fields (CreatedDate, formula values) are available. Use them to create or update related records. Records in Trigger.new are read-only.

Rule of thumb: before = same-record changes and validation; after = related-record changes and logic needing the Id.

apex-triggertriggerfundamentals