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
padmapadma 

update field in the existing record writing trigger

Hi all,

How to write a trigger to update a existing record fields.can any one explain?

thanks,
HDoshi.ax1738HDoshi.ax1738
When you would like to execute trigger? Before update takes place or after update. Generally we need before trigger to validate the changes (like validation rule should not fail or prevent update). After trigger is to update other object fields.

To update field1 with value of Field2:
Trigger updateFields on TestObject__c (before update){
  for (TestObject__c obj: trigger.new){
    field1__c = field2__c;
  }
}

I hope it answer your question.