How to set created date for a test record in test class in Salesforce?

How to set created date for a test record in test class in Salesforce?

Sample Code:

     Employee__c emp = new Employee__c(Employee_Name__c = ‘Testsing’);  
     insert emp;  
     Test.setCreatedDate(emp.Id, DateTime.newInstance(2000,10,10));  

Check the below link for more information

https://developer.salesforce.com/docs/atlas.en-us.200.0.apexcode.meta/apexcode/apex_methods_system_test.htm#apex_System_Test_setCreatedDate

Cheers!!!

Leave a Reply