I need to call two functions where the second function need to wait for the first function to finish its execution and to be delayed by 10 seconds. What I have in mind that after the fist function finished and after 10 seconds has passed, only then the second function should be invoked. It is an apex code related question.

2 Answers 2


In apex you can not have wait time. You can not suspend a thread. If you use while loop to create such time gap then you may face 10 seconds transaction time limit. I would suggest you make use of visual force page and have your control returned to page and then via JavaScript call your second function after 10seconds.


You can use action function to delay the invoking method only if you are using visual force page. In Apex there is no function to delay the code execution. You can use loop something like this but it's not a best practice to do it.

Integer start = System.Now().millisecond();
        while(System.Now().millisecond()< start+10){ 

There is an idea posted for this function but Salesforce does not seem to implement it asIn the mutli-tenant world, a sleeping thread is one that cannot be used by another customer. If this happens once and again, yeah, it's fine. But, if used poorly, this could harm our service.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.