0
Integer delay = 1;
for(Integer i=1;i<=5;i++)
{
    System.debug('Print '+i);
    Long sTime = System.now().getTime();   
    while ( (System.now().getTime()/1000 - sTime/1000) < delay){}
}

When I executed the above code in anonymous window and checked the log, it is printing only 4 and 5. not sure why it is skipping 1,2 and 3.

2 Answers 2

0

It will print all the numbers. But as the log size is high so it is skipping some part of lines in that start. You can find METHOD_ENTRY *** Skipped xxxx bytes of detailed log at the starting of the log file which means some line are getting skipped because of the log size.

You can change the log level of Apex to Debug and remaining to none so the it only generates small log file so you can see all the values.

enter image description here

1

Keep the Log Level for Apex Code as DEBUG and rest all to ERROR.

Integer delay = 1;
for(Integer i=1;i<=5;i++) {
    System.debug('Print '+i);
    Long sTime = System.now().getTime();
    while ( (System.now().getTime()/1000 - sTime/1000) < delay){}
}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .