function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
UnknownUserUnknownUser 

Trigger Update After Account Merge

I have an (after insert, after update) on Opportunity. I monitor the (AccountId) for changes.

 

trigger updateOpportunity on Opportunity (after insert, after update)
{
    Set<Id> opiIds = new Set<Id>();
   
    for (Opportunity opp : trigger.new)
    {
        if (System.Trigger.isInsert) {
            oppIds.add(opp.Id);
        }
        if (System.Trigger.isUpdate) {
           if (Util.hasChanges(fieldsTracked, opp, trigger.oldMap.get(opp.Id))) {
           oppIds.add(opp.Id);
           }
        }
    }
    if (oppIds.isEmpty()) {
        return;
    }
// Do some stuff

 

If I physically move the Opportunity from one Account to another, the trigger fires as expected. But when I merge two accounts, the opportunity thereotically changes it's parent association to the new AccountID, and my trigger monitors changes to this filed, but the trigger doesn't fire.

 

Is there a function to monitor a merge differently than an update? trigger (after merge) isn't accepted, and (System.Trigger.isMerge) isn't accepted either.

 

Yes the Master is the new Account, and the Opportunity is associated to the old Account which gets deleted after merge. So one would think that the Opportunity is getting updated with a new AccountId, but if (Util.hasChanges(fieldsTracked, opp, trigger.oldMap.get(opp.Id))) still produces 'FALSE'.

bob_buzzardbob_buzzard

When you say your trigger doesn't fire, does that mean the the trigger code isn't executed, or that it is executed but can't determine any changes have been made?

eric_deveric_dev

Hi,

Did you find a solution to catch Accounts merge process?

 

i have a workflow on a Contact object (ISCHANED(AccountId) rule) that doesn't fire when Account is merged.

 

 

Thanks

Eric

krprkrpr

A single merge operation fires a single update event for the winning record only. Any child records that are reparented as a result of the merge operation do not fire triggers.

Mark HartnadyMark Hartnady
Thanks @krpr !