Created
November 27, 2015 11:05
-
-
Save pomu0325/8b55608a9ca02dd5390b to your computer and use it in GitHub Desktop.
update Task.WhoId to ConvertedContactId for invisible Tasks related to converted Leads (Shared Activities enabled)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Map<Id, Lead> ls = new Map<id, lead>([select Id, ConvertedAccountId, ConvertedContactId from Lead where IsConverted = true]); | |
Task[] ts = [select WhoId, WhatId, (select Id from TaskRelations) from Task where WhoId in :ls.keySet()]; | |
system.debug(ts.size()); | |
TaskRelation[] deletes = new TaskRelation[]{}; | |
TaskRelation[] inserts = new TaskRelation[]{}; | |
for (Task t : ts) { | |
for (TaskRelation tr : t.TaskRelations) { | |
deletes.add(tr); | |
} | |
TaskRelation tr = new TaskRelation(); | |
tr.TaskId = t.Id; | |
tr.RelationId = ls.get(t.WhoId).ConvertedContactId; | |
inserts.add(tr); | |
} | |
delete deletes; | |
insert inserts; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment