A flow to clone a hierarchy of any depth
A user on the hub wanted to clone campaign hierarchies (just the campaigns, not the members). I thought that it just might be possible using visual workflow, but had no idea what i was in for…
I managed to pull it off, and stay reasonably within governor limits by using some well-placed screen elements. Screen elements, after all, start a new transaction, which resets the limits.
I learned a lot working through this challenge, and will try to lay out the key findings in this post.
The basic idea was to approach it one ‘level’ at a time. So start with a parent campaign (A) and clone it (A1) then query all of the campaigns (B) where B.parentID = A.id, and make copies of those under A1. And then go through each child campaign (B) and find campaigns © where c.parentId = b.id, and so on…
I used a subflow to do most of the lifting. The subflow takes two IDs as inputs: the existing
Continue reading →