function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

Problems with accessing history table.

Hi I have checked the trak history option for an object that I have.But I am not able to understand how to access the old values and new values.


For exaple I track the history of an object Customer.It has a field "Status" which is a Double.


How am I able to access this field status when the record in this object is updated??


my query would be


List<Customer__c> customerObj = [select oldValue,newValue from Customer__c where Parentid =: <some id over here >] ;


How would I access the newValue of the Status field ?


how do I get to see what the new status is??




There is a new table where history entries are stored. Each object that has history tracking enabled has an own table. In our case it would be the following:


Select p.OldValue, p.NewValue, p.Id From Customer__History p





Thank you,


But how do you access what has been changed and what were the old values and what are the new values??

For example I do an update on the "Status__c" (Double) field of "Customer__c".In the history table I have OldValue and NewValue.How do I work with these fields??

What excactly do you want to do? Are you implementing an update trigger? If yes, there you can access old and new value with "Trigger.old" or "".

I am trying to get a list of history of a record, trying to track the changes to that record.For example I have a "customer" object.He has email,status fields in there.Now sometime in the past the email might have been changed, sometime the status might have changed.So I need to track what fields were changed.What were the old fields and what are its new values.So that a list can be generated of that object with the same parentId.Can I do this with the history object provided by Salesforce.How can I do this?


When I look into the history object all that I can see is Old Value fields and New Value Fields.How do I access the information present inside them.




Did you ever successfully use OldValue or NewValue? As I understand it, they are "Any Type" which means they take on the type of the field identified in the "Field" field. I'm having trouble using OldValue or NewValue in an if statement. I even tried setting an appropriately typed variable equal to OldValue prior to trying the if statement.


No luck.


Does this mean that no one is using OldValue, NewValue in APEX code?


I can't believe that.