Search code examples
salesforceapex-code

Want time delay before function call in apex code


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.


Solution

  • 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).