0 votes
1 view
in Salesforce by (11.9k points)

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 objects.

1 Answer

0 votes
by (32.1k points)

Triggers aren't granular.  When using the before update trigger, you can use variables like the Trigger.New and Trigger.OldMap in order to correlate each 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

    }

}

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...