+ Start a Discussion

Update only changed objects



i'm working on a visualforce page that will help mass-update opportunities.  For the sake of this discussion, you can assume that all of the opportunities are in a pageblock table, with the stage and expected closed date being editable.


I've got it so there's a button that will update all of the opportunities, but it will go ahead and update *all* of the opportunities -- including ones that didn't have any values changed.


How would you recommend building something so only the opportunities that are actually changed get updated?  I don't want to do some sort of very specific wrapper, because I'm taking advantage of the date picker that comes with <apex:inputField /> on an sObject field.



Michael Lee

Certified Salesforce Developer, Administrator




I don't know if i'm understanding your situation correctly, so let me know if I'm way off =)


When loading the table, you could keep a copy of the records in a separate list.


Then when doing the update, you could iterate through the records in the table and compare them to the records in your separate list to see which ones actually changed (I think even record1 == record2 might work for this instead of checking each individual field) and only update the ones that did.