For some reasons I had to implement a ControllerExtension with a custom save methods which delegates the actual DML to a batch. I only want to fire this batch if any (or specific) fields have been changed by the user.

Is there an easy way to find out which field changed?

The only potential solution is to keep the old state in the constructor and then loop over all fields and compare them. That sounds way to complicated ;).

1 Answer 1


I think you are right - keep the original state by cloning the sobject in the constructor then compare this with the curent state on save.

Using equals on sobjects does compare all fields - see the docs: "For sObjects and sObject arrays, == performs a deep check of all sObject field values before returning its result."

But if you're interested in specific fields, compare these one-by-one.

You must log in to answer this question.

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