Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
update Task.WhoId to ConvertedContactId for invisible Tasks related to converted Leads (Shared Activities enabled)
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
You can’t perform that action at this time.