Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
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

    }

}

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...