public class LeadReparentChatTranscript { public static void doUpdate(Map convertedLeadsWithContactIds) { //convertedLeadsWithContactIds, key is the LeadId, value is the ConvertedContactId; //go through and get all the corresponding Transcript records List tList = new List(); tList = [SELECT Id, LeadId, ContactId FROM LiveChatTranscript WHERE LeadId IN: convertedLeadsWithContactIds.keySet() LIMIT 10000]; if (!tList.isEmpty()) { for(LiveChatTranscript l : tList) { l.ContactId = convertedLeadsWithContactIds.get(l.LeadId); } update tList; } } static testMethod void doTest() { Map convertedLeadsWithContactIds = new Map(); //create a contact Contact testContact = new Contact(LastName='Smith'); insert testContact; update testContact; //create a lead Lead testLead = new Lead(LastName='Smith', Company='ACME'); insert testLead; update testLead; //create a live chat visitor LiveChatVisitor testVisit = new LiveChatVisitor(); insert testVisit; update testVisit; //create a transcript LiveChatTranscript testTrans = new LiveChatTranscript(LeadId=testLead.Id, LiveChatVisitorId=testVisit.Id); insert testTrans; update testTrans; convertedLeadsWithContactIds.put(testLead.Id, testContact.Id); LeadReparentChatTranscript.doUpdate(convertedLeadsWithContactIds); } }