+ Start a Discussion

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.

SFDC Developer.

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: 


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