function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
GuyClairboisGuyClairbois 

Retrieve differences between trigger.old and trigger.new

Hi all,

 

I was wondering if there is an easy way to retrieve a list of changed fields from an update-trigger.

I mean without going through each and every field and checking whether if changed or not. I need this for an e-mail notification of the changes done on a custom object. Otherwise, whenever I add, remove or change a field, the trigger has to be updated.

 

Many thanks,

Guy

Best Answer chosen by GuyClairbois
aalbertaalbert
You could use Dynamic Apex to describe the custom object and get a list of all the fields in run-time. From there, you can loop through each field to check if the new and old values.

All Answers

aalbertaalbert
You could use Dynamic Apex to describe the custom object and get a list of all the fields in run-time. From there, you can loop through each field to check if the new and old values.
This was selected as the best answer
GuyClairboisGuyClairbois

Hmm.. Dynamic Apex is not the simplest to use..

 

What I am trying now as a workaround is the following: I can access the record history from the VisualForce Email template, so there I can also easily retrieve the changed fields.

 

But when I trigger the Email directly upon a record change, the change is not yet reflected in the record history. I solved this by delaying the Email by a bit (Time-Dependent Workflow).

 

Only challenge is to retrieve a subset of the history (only the latest changes) in my <apex:repeat> loop when retrieving the record history. I solved this now by using the RENDERED tag for only displaying today's history entries (since these particular records don't change that often) but it would be better to have a filtering/sorting option in <apex:repeat>. 

 

Let me know if you people have any other suggestions/additions.

Message Edited by GuyClairbois on 05-26-2009 08:35 AM