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

Impossible to test code covering __History tables

I've done some development of apex that reads and processes the custom object field history tables and produces that amounts to a cusotmized history related list.


That's all well and good, except that it seems that the apex test runner does not track field history, and the oldValue and newValue fields on the history object are not writable.


It's a large apex class and has taken the total coverage for my app below 75%. How can I properly test in this situation? Help salesforce!


Have you tried updating the values for test records in test methods?


Tried that, but the history table entries are never created inside test methods no mater what history tracking I have turned on.


I have the same problem. Does anyone know of a solution?


I created a wrapper class for the __history objects that can be created by hand or from an sObject and that got me over 75% test coverage for the class. It's an ugly hack but it works.


Just hit this problem too. Code coverage is one annoyance; the bigger annoyance is being unable to create the necessary set of unit test cases to be sure my code is working.


Seems that testability isn't a priority in this platform.




I plan to use 




to allow my testMethod to see data I've previously "staged" so that history comes out right.


Has any one else considered or tried this?