Skip to content

Instantly share code, notes, and snippets.

@magnet88jp
Last active July 3, 2019 12:49
Show Gist options
  • Save magnet88jp/f03624b6c8f16afa9129 to your computer and use it in GitHub Desktop.
Save magnet88jp/f03624b6c8f16afa9129 to your computer and use it in GitHub Desktop.
apex wait method sample
// Reference: http://www.xgeek.net/salesforce/a-way-to-make-thread-sleep-in-apex/
public class ApexUtil {
/**********************************************************
* Helper Method: wait
* @param Integer millisec : time for wait (millisecond)
*********************************************************/
public static void wait(Integer millisec) {
if(millisec == null || millisec < 0) {
millisec = 0;
}
Long startTime = DateTime.now().getTime();
Long finishTime = DateTime.now().getTime();
while ((finishTime - startTime) < millisec) {
//sleep for parameter x millisecs
finishTime = DateTime.now().getTime();
}
// System.debug('>>> Done from ' + startTime + ' to ' + finishTime);
}
}
@AharonShachar
Copy link

well it killing the CPU. :-(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment