Skip to main content
Hi All,

I have trigger and handler class and trying to implement the merge operation. I'm getting the error as "Merge failed. First exception on row 0 with id 0012h00000UXvezAAD; first error: ENTITY_IS_DELETED, entity is deleted: " 

when I try to merge the account if I change the email id on account from UI.

My Trigger Code:

trigger AccountTrigger on Account (before insert, after insert, after update, before update)

{

if (Trigger.isAfter) { if (Trigger.isUpdate) { AccountTriggerFacade.onAfterUpdate(Trigger.new);

}

}

}

Apex Class Code:

-------------------------

public static void onAfterUpdate(List<Account> triggerNew)

{

DuplicateAccountMerge(triggerNew); system.debug('****************DuplicateAccountMerge');

}

private static void DuplicateAccountMerge(List<Account> triggerNew) {

Set<String> emails = new Set<String>();

Map<String, Account> masters = new Map<String, Account>(); system.debug('****************DuplicateAccountMerge1'); for(Account acc : triggernew){ emails.add(acc.PersonEmail); } emails.remove(null); for(Account acc: [SELECT PersonEmail FROM Account WHERE PersonEmail = :emails AND Id NOT IN :Trigger.new])

{

masters.put(acc.PersonEmail, acc);

}

for(Account acc: Triggernew)

{

Account master = masters.get(acc.PersonEmail); if(master != null)

{

merge master acc;

}

}

}

 
1 respuesta
  1. 12 feb 2021, 09:04
    A similar issue is discussed here. I recommend taking a look at that post to learn how to avoid this error
0/9000