Search
Close this search box.

Lead Field History on a Contact Record

Red Argyle Logo without name
Red Argyle logo

It’s always helpful to know the history of Contact that originated as a lead. But when a Lead in Salesforce is converted you lose that history. Recently we ran into that issue and needed to display a Lead’s Field History on the converted Contact’s page. This makes sense because you may want to see the changes that occurred in certain fields before that Lead was converted to a Contact, however you can’t view a Lead in Salesforce after it is converted.

A report could certainly work, but we wanted to avoid the extra clicks to get to this data. Besides, it should be on the record anyway.

Thankfully, whenever a Lead is converted several fields are populated by Salesforce, including references to the Contact (Lead.ConvertedContactId), Account (Lead.ConvertedAccountId) and Opportunity (Lead.ConvertedOpportunityId) that are created as a result of the conversion process.

Armed with these relationships on the Lead record and with a little bit of Visualforce and Apex, we can create view that can be embedded in a standard Contact page layout to show the Lead’s field history.

First, the Apex controller, which will run the query to get the lead field history:

[gist id=”6006932″]

This is pretty typical Apex code – it stores the Contact record being viewed, queries the Lead and then the LeadHistory object, which contains all the field history data.

Next, the Visualforce page, which will display the field history data:

[gist id=”6006956″]

We use the Contact object as the standard controller here so we can ultimately embed the page on the standard Contact page layout. Our Apex class from above is our extension. The rest is using standard pageBlock and pageBlockTable components to loop over and render the data.

Finally, we need to add this new Visualforce page as a section on the standard Contact page layout. Because we set the standard controller to the Contact object, we can see this page in the “Visualforce Pages” list when editing the page layout. I recommend adding a new two-column Section with a hidden title and dragging the page into that section:

Save the layout, and here’s the final result. The Lead Field History will include creation, ownership changes, field updates and conversion details.

Red Argyle logo
Red Argyle logo

Related Blog Posts