+ Start a Discussion
Sri549Sri549 

How To Cover Delay Send Email Response In Test Class.

Hello Friends,

My Requirement is when you hit a button in detail page,it calls a controller(Schedulable Class) method and that adds me to schedule class.
and schedule runs after 20 minutes then emails will be sent to contact.
I have acheieved this requirement with out any issue.Now what suggestion i need from you guys is in test class like putting assert for email sent  response.
like Issuccess().
Email will be sent after 20 min and test class is running instantly.How to cover that part.
Early Reponse is much Appreciated.

Thanks
Srinivas
SFDC Developer.






 
Peter_sfdcPeter_sfdc
When you're testing async code and you need to make the async code execute immediatly, you need to use Test.startTest() followed by Test.stopTest(). 

This is documented in the Apex code developer guide that addresses the use of the Apex scheduler: 

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_scheduler.htm

The technique highlighted here works for all Async Apex mechanisms, including scheduled Apex, batch Apex, and future Apex.