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
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?

Thanks.

davidjgriffdavidjgriff

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.