Home SALESFORCEAPEX How to identify the Future Calls limits using Apex Class?

How to identify the Future Calls limits using Apex Class?

We can get the Future Call limits using Defug log like below:

Number of SOQL queries: 10 out of 100 ******* CLOSE TO LIMIT
Number of query rows: 1200 out of 50000
Number of SOSL queries: 0 out of 20
Number of DML statements: 20 out of 150
Number of DML rows: 25 out of 10000
Number of script statements: 2500 out of 200000
Maximum heap size: 0 out of 6000000
Number of callouts: 0 out of 10
Number of Email Invocations: 0 out of 10
Number of fields describes: 0 out of 100
Number of record type describes: 0 out of 100
Number of child relationships describes: 0 out of 100
Number of picklist describes: 0 out of 100
Number of future calls: 11 out of 10 ******* CLOSE TO LIMIT

So using Apex Class we can identify the Future Calls counts:

using the following methods we can identify the future Calls limits

getFutureCalls()

Returns the number of methods with the

@future

getLimitFutureCalls()

Returns the total number of methods with the

@future

How to avoid to receving the “Too Many Future Calls” during the Test Classes?

using the following combination of Apex Method, we can avoid to receiving the “Too many future calls” during Tests:

Sample Code:

 if(Test.isRunningTest() && Limits.getFutureCalls() >= Limits.getLimitFutureCalls()) {
     system.debug(LoggingLevel.Error, '@Future Calls method reached limits so, please skip the process...........');
 } else {
     callYOURFutureMethod();
 }

You may also like

Leave a Comment