You need to sign in to do that
Don't have an account?
Mitchell McConnell 2
How to fake date for testing
Hello all,
I have been away from Salesforce development for a few years, and am just getting back to it. I have an app I have created in my developer sandbox, and I am creating some REST code with Python for testing.
I have some Apex code that causes things to happen based on the date. So I might have something that should happen one month from today. How can I cause my instance to run with a date that is in the future, so I can test my code?
Thanks,
Mitch
I have been away from Salesforce development for a few years, and am just getting back to it. I have an app I have created in my developer sandbox, and I am creating some REST code with Python for testing.
I have some Apex code that causes things to happen based on the date. So I might have something that should happen one month from today. How can I cause my instance to run with a date that is in the future, so I can test my code?
Thanks,
Mitch
Please specify for what field you wanted to fake the date.
If you want to fake the created date of a record. You can always achieve it with setCreatedDate of Test Class (https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_test.htm) method.
Or if you want to set a date to a custom field you can achieve that like I hope it helped you. In case I didn't get what you actually needed. Please post more info.
Sachin,
Thanks for reminding me about the Test classes. Since this is a private sandbox, I have not (yet) created my test classes.
When I do, I will use your suggestion.
Thanks,
Mitchell