Development questions

Why are records in Trigger.new read-only in after triggers?

DevelopmentMediumWiproCapgeminiKPMG

In after triggers the records have already been written to the database (not yet committed), so the save operation is complete. Modifying Trigger.new fields would have no effect on what was saved, and Salesforce throws Record is read-only.

To change the same record in an after trigger, query a fresh copy (or create a new SObject instance with the Id) and perform DML on it. This re-fires triggers, so guard against recursion. Better, move same-record logic to a before trigger.

apex-triggertriggerdml