Is there any way I can transfer Lead History
tracking section data to the Account
record when that lead gets converted to an account?
3 Answers
As mentioned above, you cannot insert into the history tables of SF.
You can create vf page that will show both history from the Lead History and the related Account. Create custom button in the account layout that will open this vf Page. Or even embed this vf page inside the account layout instead of the standard history related list
-
I would prefer this method as my preference is not to use any additional objects. If you're sticking with standard layouts across your org, the approach given by Folkert will work for you.– abhiFeb 19, 2017 at 16:38
-
Unfortunately, the AccountHistory
object (where the history is tracked for account, each change is a row) does not support insertion through Apex or API.
I would suggest creating a custom sObject, for instance Converted_Lead_History__c
which you can then fill with the history from the LeadHistory
object for the converted Lead.
Write a trigger on Lead and check whether ConvertedAccountId
is filled. If that's the case, create a Convert_Lead_History__c
record for each record in the LeadHistory
list for this Lead, then fill a lookup from this new sObject to the newly converted Account.
You could also add the following piece of code in your lead conversion process (if you're using Apex for lead conversion).
List<Converted_Lead_History__c> convertedLeadHistory = new List<Converted_Lead_History__c>();
List<LeadHistory> oldLeadHistory = [SELECT Field, NewValue, OldValue FROM LeadHistory WHERE LeadId =: convertedLead.Id];
for (LeadHistory lh :oldLeadHistory) {
convertedLeadHistory.add(
new Converted_Lead_History(
// fill the fields here
)
);
}
insert convertedLeadHistory;
Don't forget to bulkify it if you are using this code in a trigger!
No, you cannot write records to the History tracking tables.
You can provide a link to view the Lead History related list page, though not sure how well that will work in Lightning Experience. But this is least invasive from development standpoint.
You can develop a Visualforce page or Lightning Component that queries both Account and Lead History then sorts them by Date. Caveat, if you query the fields yourself make sure to check field level security of current user before rendering the data otherwise you may be inadvertently exposing data to users who should not see it.