I have a simple requirement of capturing the "newest" created date when two leads are merged. As far as I can tell the only way to detect a lead merge would be in delete trigger and look for MasterRecordId being set. Is there someway to detect the merge using a workflow or process builder?

Also, while the docs state the CreatedDate of the oldest record is always kept, does this mean the newest record is always deleted?


Using the after delete trigger via MasterRecordId is documented to be the only way to trigger on a merge:

If your application requires special handling for deleted records that occur as a result of a merge, you need to use the after delete trigger event.

This would be the place to grab their CreatedDate values and populate the newest onto the winning record. Be aware that not all of the deleted records in the after delete trigger's context variables are necessarily from a single merge operation, or even all from merges period.

If you wanted to detect the merge in workflow or Process Builder, you could use a very simple after delete trigger to, for example, populate a Merged_Ids__c field with the losing records' Ids, and fire on that change. However, your process/workflow would not be able to capture data from the losing, and already deleted, records.

During a merge, the update trigger is fired on the winning records and the before delete trigger on the losing records, but no merge information is available during those trigger invocations, so you cannot detect that it's anything other than a normal update or deletion.

The newest record may or may not be deleted during a merge; it depends on which record is selected as the winning record.

  • 1
    great answer. I was afraid that last statement would be true. Makes implementing this simple requirement much more complex unfortunately. – NSjonas Feb 24 '18 at 21:09
  • 1
    Unfortunately I've found that almost anything merge-related ends up being fairly complex to implement! – David Reed Feb 24 '18 at 21:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.