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
pintoo rajputpintoo rajput 

How to create LeadHistory in TestClass???

Shiva Ramesh @ xcdhrShiva Ramesh @ xcdhr
try this

Leadhistory lh = new Leadhistory(Field='<API namwe of field on history tracking is enabled>',;
insert lh;
pintoo rajputpintoo rajput
Thanx Shiva 
But it is not working 
Error-System.TypeException: DML operation INSERT not allowed on LeadHistory
Martijn SchwarzerMartijn Schwarzer
Hi there,

Unfortunately, you cannot create LeadHistory in test classes because the history object will not be inserted during test execution.

The only workaround you have is to use the @isTest annotation with (SeeAllData=true), which will expose the data in your org to the test class.

Please keep in mind that there is no guarantee that the LeadHistory objects are filled in the org you are running your test in, so please make sure your test code doesn't break if the data is not available.

Hope this helps and good luck!

Martijn Schwärzer