Fire trigger update when updating a specific field

How can I start a trigger before updating, only one or several specific fields are updated, and do not start when other fields are updated, since it causes a duplicate record in another object.

+6
source share
1 answer

Triggers are not so granular. In the trigger before updating, use the Trigger.New and Trigger.OldMap variables to compare each new record to see if the fields that interest you have changed.

 for (Opportunity newOpp : Trigger.new) { Opportunity oldOpp = Trigger.oldMap.get(newOpp.Id); if (oldOpp.Name != newOpp.Name) { // do something } } 
+14
source

Source: https://habr.com/ru/post/904692/


All Articles