Best practice for updated related records/tasks during a lead merge? - Answers - Salesforce Trailblazer Community
Trailblazer Community
Ask Search:
Andrew AtiyaAndrew Atiya 

Best practice for updated related records/tasks during a lead merge?

Hello!

My org relies heavily on sequenced chains of tasks to help agents make timely follow ups on leads.  Whenever an open task is closed, another is created for a future follow up.  It works really well in most cases.

Merging duplicate leads currently breaks this functionality, by combining the open task chains from both the master lead and the non master lead onto the master lead.  The result is a lead with redundant open tasks (activities) on it.  FYI, we use Salesforce's native duplicate lead merge functionality. 

The clear desired fix is for the tasks from the nonmaster (deleted) lead to be automatically closed when the merge event takes place.  This doesn't appear to be configurable, so we tried to solve it with process and flow.

We attempted to create an autolaunched flow triggered before delete of a lead that would loop through related tasks and close them, but it appears that whatever salesforce is doing during a merge scenario results in a deleted nonmaster lead but doesn't fire flow's "before delete" trigger.

We tried a process builder/flow combination that would watch for a task's WhoId to be updated to a new leadId, but again even though the result is that the same tasks get a new WhoId, the merge function operates in such a way that doesn't fire process builder (we can get the process to fire when manually updating a task's WhoId field).

We even tried modifying the autolaunched flow to watch for the deletion of a Duplicate Record Item and retrieving the lead/task chain from there, to no avail.  Flow can see the DRI get deleted but that happens too late the close the tasks.  By that time the tasks have already be assigned to the new master lead.

We'd like to be able to solve this without custom apex, or with as little apex as possible.  What are our options?  Does anyone understand what is happening during a duplicate merge operation well enough to explain our options here, what we can automate off of?

Again, the ultimate goal is to automatically/programmatically close tasks from a nonmaster lead before merging them with a new master lead.

Thank you!

Andrew
Andreea DorofteiAndreea Doroftei

Hello Andrew, 

The requirement surely is interesting, let's see if we can get at least closer to a solution. 

Firstly, would you be open to move the de-dupe process in a flow, perhaps? What I mean by that is to try to reduce the number of situations where there will be a need for manual merge. 

Secondly, what are you de-duping on? I'm guessing maybe e-mail / first name / last name/ company? 

What I'm thinking is to have an identifier on the Task (custom field) which would retain some data from the initial Lead it was assigned to, therefore us being able to identify the duplicate one and close/delete it post merge. Considering that we want to keep it as declarativ as possible, using maybe one or two extra fields wouldn't be a problem.