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
adi salesforceadi salesforce 

Trigger to get old record values into new record in account

v varaprasadv varaprasad
Hi

Please check once below sample code:
 
trigger oldValues on account(after update){
   

   for(account acc : trigger.new){
       //oldvalues
      string oldphone = trigger.oldmap.get(acc.id).phone;
	  system.debug('==oldphone=='+oldphone);
	  //New values
	  string newphone = acc.phone;
	  system.debug('==newphone=='+newphone);
	  
   
   
   }



}


Hope this helps you!
If my answer helps resolve your query, please mark it as the 'Best Answer' & upvote it to benefit others.


Thanks
Varaprasad
Salesforce Freelance Consultant/Developer/Administrator
@For Salesforce Project Support: varaprasad4sfdc@gmail.com


Salesforce latest interview questions  :
https://www.youtube.com/channel/UCOcam_Hb4KjeBdYJlJWV_ZA?sub_confirmation=1
AshishkAshishk
Try below code:-

Just copy old value in same field in trigger.new.
trigger updateAccount on account(before update){
   for(account a: trigger.new){
     a.Name = trigger.oldmap.get(a.id).Name;
   }
}

 
Raj VakatiRaj Vakati
Try this 
 
trigger updateAccount on account(before update){
   for(account a: trigger.new){
If(a.Name != trigger.oldmap.get(a.id).Name){
     a.Name = trigger.oldmap.get(a.id).Name;
}
   }
}