function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
TheReportDoctorTheReportDoctor 

Read-only when After Insert while updating the fields of the trigger.new

The following trigger gives me this error:

 

Apex trigger LineItemTest caused an unexpected exception, contact your administrator: LineItemTest: execution of AfterInsert caused by: System.Exception: Record is read-only: Trigger.LineItemTest: line 3, column 9    

 

=============================

 

trigger LineItemTest on OpportunityLineItem (after insert) {
    for(OpportunityLineItem li: trigger.new) {
        li.Description = 'This is the replacement';
    }
}

Best Answer chosen by Admin (Salesforce Developers) 
TheReportDoctorTheReportDoctor
Solved my own problem.  The tigger needs to be BEFORE INSERT.