All Ideas

Idea Details

Post an Idea
This idea has been merged into another idea. To comment or vote on this idea, please visit IsChanged function in Apex.
0  Points voting closed
Open
Idea has been posted. Give it an upvote or downvote.

Provide methods on SObject to identify dirty fields

Apex & Visualforce

We'd like methods on the generic SObject in Apex that lets us identify if a field has changed since it was retrieved from the database.

Something like:

class SObject
{
  /**Returns true if any fields have been assigned to since the record was retrieved from the database*/
  public Boolean hasChanged() 

  /**Returns true if the field has changed since it was returned from the database */
  public Boolean hasChanged(String fieldName)

  /**Returns the value the field had when it was returned from the database */
  public Object previousValue(String fieldName)
}


A few use cases:
  • Sometimes additional validation rules (Apex validation rules) need to be applied if a value changes -- right now, this requires querying the object from the database a second time (governor limit cost, performance cost) and comparing the field values
  • For FLS enforcement, it is the Apex developer's responsibility to reject an Update/Upsert if the user doesn't have isUpdateable() on a field. This is huge burden for ISVs building managed packages. We had to implement: https://github.com/patronmanager/apex-dml-manager in order to hack around the lack of support for identifying dirty fields.
We're basically talking about the equivalent of Trigger.old and Trigger.new but within the context of a regular Apex execution context.

We appreciate that storing the previous value on the SObject could have VF view state and heap size implications so the implementation of previousValue() is a little messier -- a 'trackChanges()' method on SObject that could be called immediately after retrieval .. or perhaps an argument to Database.query to make the objects track changes

· Flag

  • Upvotes
  • Downvotes

Ideas

Apps

from AppExchange

Questions

Help us to keep IdeaExchange clean by pointing out overlapping ideas. We'll investigate your suggestion and merge the ideas if it makes sense.



 

 

Thanks for your merge suggestion. We will review it shortly and merge the ideas if applicable.

Salesforce takes abuse situations very seriously. Examples of abuse include but are not limited to posting of offensive language or fraudulent statements. To help us process your request as quickly as possible, please fill out the form below describing the situation. For privacy and security reasons, the final outcome of an abuse case may not be revealed to the person who reported it.


 

Thank you for your feedback. We take abuse seriously and will investigate this issue and take appropriate action.