If you need something like the sleep () function, one way to do this is to make an http service call that will sleep the requested amount of time. This is quite simple to do, and there are publicly available services for it, for example, http://1.cuzillion.com/bin/resource.cgi .
First you need to configure a new remote site in SalesForce (Security Controls β Remote Site Settings), but name it, but you want to, but make sure that the URL of the remote site matches the URL above and that the "Active" checkbox is selected.
After that, you can define your method in the code as follows:
public static void sleep(Integer sleepSeconds) { Long startTS = System.currentTimeMillis(); HttpRequest req = new HttpRequest(); req.setEndpoint('http://1.cuzillion.com/bin/resource.cgi?sleep=' + sleepSeconds); req.setMethod('GET'); Http http = new Http(); HTTPResponse res = http.send(req); Long duration = System.currentTimeMillis() - startTS; System.debug('Duration: ' + duration + 'ms'); }
Launch:
sleep(1); -> 08:46:57.242 (1242588000)|USER_DEBUG|[10]|DEBUG|Duration: 1202ms
source share