Salesforce Record History in Timeline view using a custom Lightning Web Component

History Timeline

Update (Sep 6 2021): The next version for this component is now available. While this post still covers basic information about the component, everything about new version is available in this post. You can now install the component via new Package link provided in that blog post. The source code is still available in on Github.

Update (Aug 2021): The next version for this component is coming soon. I am targeting to release it in no more than 4 weeks. As I am working on this only on weekends, the final date might slip little bit. You can still install current version, however I will suggest to wait few weeks and use new version instead.

Update (Aug 26, 2020): The post is updated to include changes for Test classes and details on how to install the component.

Salesforce introduced Lightning UI back in 2015. Since then, there has been lots of changes, improvements in the UI. In 2020, the UI is certainly more usable and configurable compared to Salesforce classic; however, I think there are still many components that require transition or improvements in Lightning. This post covers about one such similar component which I was hoping to get an upgrade to new UI long back.

The related list of History in Salesforce Classic looks like this.

Salesforce Classic History Related List
Salesforce Classic History Related List

When it was made available in Lightning with Summer ’17 release, it was transformed into a simple table with New and Old value columns, the new filter addition is welcome though. As of September 2021, the UI is still the same, it may change in future.

Salesforce Lightning History Related List
Salesforce Lightning History Related List

The current tabular UI might serve the purpose for some, but I was actually looking for a richer UI to present the data. I looked through the components on Lightning Design System website and my search ended with this component. I was able to find couple of good components on the web and Salesforce AppExchange however, I decided to build one with content customized specifically for history data.

Rest of post will cover some technical, functional aspects of the component. There are some limitations as well as planned enhancements mentioned below. Finally, you can find ways to install in your own org.

Technical Aspects

  • It is built with combination of Apex and Lightning Web Components.
  • Apex Code takes care of fetching the history data, defining & building wrapper structure to show on UI.
  • Object and Field level access control is handled in the apex code. If the logged in user does not have access to object or field, the component won’t show it.
  • Search functionality is handled completely on client side through JavaScript. There are Search tag arrays built into wrapper to filter records based on User input in text field.
  • The Apex Code is using few reusable methods from SystemUtilities apex class. These can be used outside the scope of this component.
  • Writing Test Class for classes centered around OOB history objects is difficult. In order to cover the apex class written with this component, the test classes will need to have ‘SeeAllData’ set to True. Hence, for your specific org, you can create a test record and fetch that in the test class which is provided in the repository. I was able to find a way to create history data using Static Resources and feed that to the Test class to get required code coverage.

Limitations

  • Percent fields are shown without Percent signs. They will show up just like normal number fields.
  • For Encrypted fields, only the “change” event is shown, the actual or masked value is not shown.
  • The content inside component does not auto-refresh if it is open on UI and data changes. Hence, the refresh button is available to force manual refresh.

Planned Enhancements

  • Improve Search Mechanism; move away from linear search, more towards dictionary like approach.
  • Move the configuration to Custom metadata.
  • Add additional filters for date, users with an option to configure default filters.

How can I get it in my Org and configure it?

Please visit this post to see updated version and ways to install.

Let me know if you have any questions, comments or any other type of feedback.