+ Start a Discussion
Bhart KumarBhart Kumar 

why records fetched inside after triggers or via trigger.old are read only? Can anyone please explain with an example?

AbhinavAbhinav (Salesforce Developers) 
Hi Bhart,

If you have encountered this error while working on Triggers. This is because once you are in an after insert/update trigger and the records are read only in that context as they have been written, but not committed, to the database.
Unfortunately your trigger is relying on the ids of the records, which means you won’t be able to use before insert as the ids won’t be populated at that time (as the records haven’t been written to the database at that point so while you can write to them, database generated fields aren’t populated).



check below to link to get clarity on Trigger.old and Trigger.new


If it helps mark it as best answer.

Suraj Tripathi 47Suraj Tripathi 47
Hi Bhart,

 This kind of error occurs if you try to update lists/record which are/is read-only in the trigger execution.
 Please refer below link it may be helpfull for you.


If you find your Solution then mark this as the best answer. 

Thank you!
Suraj Tripathi

The records are written but they are not committed into the database hence they will be read only, you can perform the DML post commit to Database