You need to sign in to do that
Don't have an account?

Created Date Over ride?
Hi all,
How to over ride the created date in the test class as past date.
Can any one he me providing the code.
Thanks in advance.
How to over ride the created date in the test class as past date.
Can any one he me providing the code.
Thanks in advance.
Test.setCreatedDate(objCusWct.id, yesterday);
All Answers
1. Using Test.loadData.
In this option you will need to create a .csv file and enter the necessary data in the .csv file. Once the csv file is ready, upload the csv file as a static resource.
the Sample CSV used in the blow code is here - https://www.dropbox.com/s/7vnnu4draf1db2q/testCases.csv?dl=0
a. Click Develop | Static Resources, and then New Static Resource.
b. Name your static resource testCases.
c. Choose the file you just created.
d. Click Save.
Then Call Test.loadData in a test method to populate the test case data.
Code Example:
2. Using JSON.deserialize
You can create sObjects in memory with arbitrary CreatedDate values by using JSON.deserialize. This doesn't enforce the normal read-only field attributes that prevent you from setting a createdDate value.
Code Example:
If this helps, please help others by chosing it as an answer.
Follow the steps given in this article to set created date on a record. https://help.salesforce.com/apex/HTViewSolution?id=000181873&language=en_US (https://help.salesforce.com/apex/HTViewSolution?id=000181873&language=en_US)
Regards,
Siv.
Test.setCreatedDate(objCusWct.id, yesterday);