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
Fire a update trigger when particular field is updated
Asked Answered
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
}
}
Can you give me a small example. I am kind of new to salesforce –
Pugilism
Map<ID,sObject> NewRecords = Trigger.NewMap;
salesforce.com/us/developer/docs/apexcode/… –
Sike © 2022 - 2024 — McMap. All rights reserved.