Skip to content

Instantly share code, notes, and snippets.

@sabadoc
Forked from magnet88jp/ApexUtil.cls
Created May 31, 2018 15:10
Show Gist options
  • Save sabadoc/224c6410ede25928d4900de030a78e9e to your computer and use it in GitHub Desktop.
Save sabadoc/224c6410ede25928d4900de030a78e9e 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);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment