I am trying to display Old values and New values of a record whenever certain fields are edited on a record. How do we achieve this.

Edit: I am getting the Oldmap and newmap from the trigger context and comparing the old and new to check if the fields are changed and add them to a list.

The point where I was stuck is if there is a reference field like lookup to a different object we wouldn't get the values we can only get the Id of the record which is not very useful and this would mean more queries.

Can you point me in right direction

1 Answer 1


The thing you're describing is the standard field history tracking feature, at least for the "show old and new values" part of it.

It's a related list on whatever object(s) you have it enabled on, and you can display a related list in Visualforce using <apex:relatedList>

  • Thanks Derek. I kind of get that. However what I am after is something different.If I have a list of 5 fields on (3 text and 2 lookup) for example I would like to show the old and new values on a page . For history tracking I need to setup for only these 5 fields if I have to display with Related list tag.
    – Badduboy
    Commented Jul 14, 2020 at 12:58
  • @Badduboy Then you need to edit your question to include more details and show us what you've tried so far (and point to a specific part that you're stuck on). If your question sounds too much like a request to "do my work/research for me", it's liable to be closed by the community.
    – Derek F
    Commented Jul 14, 2020 at 13:00
  • Thanks Derek. New to this community. I have edited my question now.
    – Badduboy
    Commented Jul 14, 2020 at 13:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .