• ianzepp.ax604
  • NEWBIE
  • 0 Points
  • Member since 2009

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies

The APEX Language Reference and Force.com Developers Guides (among others) state that the New collection can be written to in a Before Insert trigger.   Unfortunately when I try to do so, I get a 'Collection is read-only' error.   What gives?

 

 Sample code:

 

 

trigger ProductKits on OpportunityLineItem (before insert)
{

 

//test, just add an opportunitylineitem to trigger.new
            OpportunityLineItem bLineItem = new OpportunityLineItem();
                    bLineItem.quantity = 1;
                    bLineItem.UnitPrice = 100.00;
                    bLineItem.Opportunityid = '006S0000002pi1Y';
                    bLineItem.pricebookentryid = '01u80000003LOTJAA4';
            trigger.new.add(bLineItem);

 

}