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 fired 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? I reviewed this post (Account Merge Trigger Execution Order) which says that "child records that are reparented as a result of the merge operation do not fire triggers, but unfortunately my trigger related to Opportunity is being fired.
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);
}
}
2 weeks later
logic? A scheduled job, time-based workflow, etc.