How do I fire a before update trigger only one or some particular fields are updated and not fire when other fields are updated as it causes duplicate record in other object
Triggers aren't granular like that. In the before update trigger, use the Trigger.New
and Trigger.OldMap
variables to compare each new record to see if the fields you're interested in have changed.
for (Opportunity newOpp : Trigger.new) {
Opportunity oldOpp = Trigger.oldMap.get(newOpp.Id);
if (oldOpp.Name != newOpp.Name) {
// do something
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With