I have custom button which when clicked redirects to VF page, VF page calls some controller,
But I want as soon as custom button is clicked it should process to VF page waits for 2 secs and then redirect back to detail page of the record.
How to achieve that? Not getting any help from google
Best Answer
This is the most simple way I could imagine. Other alternatives abound, as well.
As a side note, I'd avoid DML this way, because it does open up the possibility of XSS attacks (however unlikely that would be). Instead, offer the button here as a means of confirmation, then return when you're done. Alternatively, simply perform the work from the button itself. There's really no need to show a page for just two seconds.
You can also show a waiting dialog while you're waiting:
Feel free to use a spinner or something instead of just a generic "please wait" message to give the illusion that something is happening (which, something is happening, but we want the user to be reassured).