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
Kathleen Elisabeth SmithKathleen Elisabeth Smith 

Merging Accounts Sets off Trigger

I have a trigger on the Opportunity object that runs after an opportunity is deleted, inserted, undeleted, or updated, or before one is deleted, inserted, or updated. We use this to start a process on the Status of an Opportunity/Contract.
  • If opportunity is "In Progress", then the account type is "Prospect"
    • 2 Weeks later, if this is still "In Progress", the account type is reverted to the previous account type (either "Lead' or "Inactive Client")
  • If opportunity is "Won", then the account type is "Active Client"
  • If opportunity is "Lost", then account type is either "Lead" or "Inactive Client"
Recently, while merging some accounts, I noticed that a couple of accounts that I had merged were reverting to their previous account type 2 weeks after the day that I had merged them. Since both accounts had opportunities merged into the master account and based on the time that the type was reverted, I was able to tell that the Opportunity_ContractTrigger was being set off when I was merging.

Has anyone had a similar issue to this when merging accounts, and what do you recommend I change in the Trigger so that it doesn't begin running when I merge accounts with opps?

Below is the code for trigger. Please let me know if you have any other questions. Thank you.

Opportunity_ContractTrigger
trigger Opportunity_ContractTrigger on Opportunity__c (after delete, after insert, after undelete, after update, before delete, before insert, before update) {

    if(trigger.isInsert && trigger.isBefore) {
      Opportunity_ContractTriggerHandler.OnBeforeInsert(trigger.new);
      
    } else if(trigger.isInsert && trigger.isAfter) {
        Opportunity_ContractTriggerHandler.OnAfterInsert(trigger.newMap);
        
    } else if(trigger.isUpdate && trigger.isBefore) {
        Opportunity_ContractTriggerHandler.OnBeforeUpdate(trigger.oldMap, trigger.newMap);
        
    } else if(trigger.isUpdate && trigger.isAfter) {
        Opportunity_ContractTriggerHandler.OnAfterUpdate(trigger.oldMap, trigger.newMap);
        
    } else if(trigger.isDelete && trigger.isBefore) {
        Opportunity_ContractTriggerHandler.OnBeforeDelete(trigger.oldMap);
        
    } else if(trigger.isDelete && trigger.isAfter) { 
        Opportunity_ContractTriggerHandler.OnAfterDelete(trigger.oldMap);

    } else if(trigger.isUnDelete) {
        Opportunity_ContractTriggerHandler.OnUndelete(trigger.new);
    }
}
Anthony FlaggAnthony Flagg
I'm having a similar issue, so I'm commenting to see if someone can help both of us haha.
Kathleen Elisabeth SmithKathleen Elisabeth Smith
@Anthony Flagg I figured out what is causing the issue for me. When I merge accounts, the opportunity being re-parented is updated, as the related account is changing. Since this counts as an update, this fires the Opportunity_ContractTrigger, which sets off the related scheduled job. 

Now to figure out how to keep merged accounts from firing the trigger....