+ Start a Discussion

Field update from formula?

Hello all,


I am trying to create a trigger that sets a Currency Field in the Object, to the result of what a formula was.  The issue is that when i do this, it says 


Error:Apex trigger UpdatePriceValue caused an unexpected exception, contact your administrator: UpdatePriceValue: execution of AfterUpdate caused by: System.Exception: Record is read-only: Trigger.UpdatePriceValue: line 4, column 3


Any way around this?  I have the code below:



trigger UpdatePriceValue on Services_Selection__c (after insert, after update)


for (Services_Selection__c SS : Trigger.new)


SS.Price_Value__c = SS.Price_Formula__c;




Thanks in advance, to anyone who can help resolve this small issue.

Best Answer chosen by Admin (Salesforce Developers) 

They should be in before event not after event.

You can not assign any value to after event.