3

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 ;).

4

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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.