+ Start a Discussion

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) 
Solved my own problem.  The tigger needs to be BEFORE INSERT.