Skip to main content
i am getting this error for this trigger

trigger PriceUpdate on MyObject__c (before insert) {

   list<MyObject__c> ilist = new list<MyObject__c>();

    for(MyObject__c a:trigger.new){

        If(a.Use_Standard_Price__c == true){           

            a.Standard_Price__c = a.Price__c;

               

            ilist.add(a);

        }            

    }

    insert ilist;

}

Error: Invalid Data. 

Review all error messages below to correct your data.

Apex trigger PriceUpdate caused an unexpected exception, contact your administrator: PriceUpdate: execution of BeforeInsert caused by: System.SObjectException: DML statement cannot operate on trigger.new or trigger.old: Trigger.PriceUpdate: line 13, column 1
2 réponses
  1. 16 avr. 2019, 17:29
    Hi Gouse,

    Try the below Trigger:

    trigger PriceUpdate on MyObject__c (before insert) {

        for(MyObject__c a:trigger.new){

            If(a.Use_Standard_Price__c == true){           

                a.Standard_Price__c = a.Price__c;

               }            

        }

    }

    In before insert you don't have to use the DML Statement to overide the new records just the assign the values like above will make the respected changes.

    Thanks,

    Maharajan.C
0/9000