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).
In this instance you’ll need to clone the record (or query anew via SOQL) and make changes to the new copy of the record, then execute the update against the new copies
1 comments
This Is helpful, I was facing a similar issue. Good Job