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
feelsfdcfeelsfdc 

problem with createddate

Hi,

 

I have a batch apex calss and need to write testcoverage for it. In the Batch Apex , query with condition crateddate < Last_N_Days:7.   I have created a dummy record for the lead in test method. But here the problem is  this dummy record is failing to processed by the batch apex as its createddate is today.

 

I need to create a record in testmethod which satisfy query condition then only that record will process through. But createddate is a system variable and we cant set its value in test method.

 

Anyone has any suggesstions. Appreciate reply.

 

Thanks.

EnthEnth

I hate to suggest it, as it's bad practice, but if this is just for internal use, then manually create the data you need to get your code coverage and ensure you've indicate it's test data somehow.

 

You can request a feature activation to allow the create date to be set but this is only really for data migration.