Want time delay before function call in apex code

Yogini Mane picture Yogini Mane · May 28, 2013 · Viewed 14.3k times · Source

I want time delay before function call in apex code. I already created one delay method but it is not working as per expectation. So, is there any way to get this working.

Thanks in advance.

Answer

amrcn_werewolf picture amrcn_werewolf · May 29, 2013

Probably a better way to do this would be to break up your Apex code such that the part you want to execute later is in a separate method. You can then call this method from another method that has an @future annotation, or use the Apex Scheduler to schedule that code for a future time. Either of these methods will cause the code to be executed asynchronously after your original method has completed (the @future method is easier to implement but the scheduler method has the advantage of running at a predictable time).