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
Clap MasterClap Master 

Make copy of history object to use for testing

As many of you already know, history object are not editable.  This presents a unique issue when you have Apex classes that deal with histories, as you need to acheive 75% code coverage in your tests.  In my case, I'm dealing with Cases and CaseHistories.  The cleanest way I can come up with to test this is to (if possible) make a copy of the CaseHistory object (and call it something like TestCaseHistory) and then manually populate that along with Cases in my test code, and then run my classes against that test data.

 

The key to this, though is Can you make a copy of 'History' objects to use elsewhere?