Skip to content

Instantly share code, notes, and snippets.

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()];
TaskRelation[] deletes = new TaskRelation[]{};
TaskRelation[] inserts = new TaskRelation[]{};
for (Task t : ts) {
for (TaskRelation tr : t.TaskRelations) {
TaskRelation tr = new TaskRelation();
tr.TaskId = t.Id;
tr.RelationId = ls.get(t.WhoId).ConvertedContactId;
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.