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
jjagtjjagt 

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) 
iBr0theriBr0ther

They should be in before event not after event.

You can not assign any value to after event.

 

Cheers,