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
SFDC BeginerSFDC Beginer 

Runtime Exception in trigger

Hi everyone, this is the task :  
// Populate contact description with modified user name when user updates contact.
trigger Contact_Before_Update on Contact (before update)
{     for(   Contact c:Trigger.new)  
       {    c.Description='Contact update is successed by'+userInfo.getUserName();  
} }
// actully in for loop when I use Trigger.old, am getting run time erro. we can use Trigger.old right becaz before update we alaredy had the existing record right?  Could anyone please explain me..am so confused. when I write Trigger.new its working fine. why cant we use Trigger.old here?
sfdcMonkey.comsfdcMonkey.com
You are trying to update old value through Trigger.old, thats why the error is.
 Trigger.old is always read only. you can not set read only values in before update,
Try to update new value Trigger.new instead of Trigger.old
refer  :http://https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_triggers_context_variables_considerations.htm

Kindly let us know if it helps you, & close this query by selecting best answer if you got your solution, so this will helps other in future
 
sfdcMonkey.com






 
sfdcMonkey.comsfdcMonkey.com
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
If you find a post helpful and it answers your question, please mark it as an "Best Answer"! This will help the rest of the Community with similar issues identify the verified solution and benefit from it.