+ Start a Discussion
Kenn K.Kenn K. 

Inserting data to audit field like created date for test class

I am creating a test class and the scenario I am testing requires an older date for the created date. I know CreatedDate is an audit field and I can't write to it. Is there a workaround I could use for writing my test class?



The easy way is to use the new Test.loadData method to load some sample records from a static resource.


List<sObject> ls = Test.loadData(SObjectName.sObjectType, 'StaticResourceName');


Kenn K.Kenn K.
Ok thanks.. Let me give it a shot.