-3

How do we prevent un-necessary updates on a record? For example, a User(say A) is owner and creator of a record. There is a visualforce page which updates this record.

Can we prevent the Lastmodifieddate from being updated even though there aren't any changes to the record?

Please don't say that you have to query the record, compare the changes and then update the record.

8
  • prevent the Lastmodifieddate ? if you perform update on record then obvious Lastmodifieddate will be updated
    – Ratan Paul
    Jul 29, 2016 at 7:05
  • If anything on the record is modified ,LastModifiedDate will be changed. what is actually the problem your trying to solve?
    – EricSSH
    Jul 29, 2016 at 7:09
  • I did not modify any values in the record, but when the update operation happens, the lastmodified field is being updated eventhough there are no modifications on the record. I want to prevent the lastmodifieddate field from being updated if there are no modifications to the record. Jul 29, 2016 at 7:26
  • You can query and display a record without updating the LastViewedDate, but there are no tricks for getting around the LastModifiedDate. If an operation is performed on a record, the LastModifiedDate field will be updated.
    – martin
    Jul 29, 2016 at 7:31
  • Why update the record then if there are no changes made to it?
    – martin
    Jul 29, 2016 at 7:33

1 Answer 1

2

OPTION 1 You can create a flag and init in FALSE, when A user change any value in the visualforce you can change the value of the flag. Before update the record you must verify the value of the flag, if is true you update the record.

OPTION 2 In the constructor of the visualforce you do a backup of the record. Before update the record you compare the backup with the original record.

If they are different then you can update the record

Regards

2
  • There are 100 fields which we show up on the visualforce page. It is difficult to check each field. So, am looking for an alternative if we can prevent the last modified date from being updated. Jul 29, 2016 at 9:05
  • 2
    @SurendranadhNune - Torsen's option 2 is easy to do as you can compare the two SObjects in a single line -- without having to do field-by-field. See Apex doc
    – cropredy
    Aug 8, 2016 at 1:16

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.