3

This support article indicates that I have a limit of 250k @future methods per day. However, I can't find the corresponding Limit class function to monitor this limit. I've tried:

System.debug(Limits.getFutureCalls());
System.debug(Limits.getLimitFutureCalls());

Both of these seem to deal with a single Execution context.

I've also reviewed the documentation here, but can't find one that fits. This Exchange answer seems to indicate the answer is "you can't" but that seems preposterous that Salesforce sets a limit that you can't monitor, so I hope I'm reading it wrong.

2 Answers 2

8

As sfdcfox pointed out, this is a shared limit for all async operations in the org.

You can monitor this directly in Apex via the OrgLimits class.

Map<String,System.OrgLimit> limitsMap = OrgLimits.getMap();

System.OrgLimit apiRequestsLimit = limitsMap.get('DailyAsyncApexExecutions');
System.debug('Limit Name: ' + apiRequestsLimit.getName());
System.debug('Usage Value: ' + apiRequestsLimit.getValue());
System.debug('Maximum Limit: ' + apiRequestsLimit.getLimit());

07:45:33.31 (31463597)|CODE_UNIT_STARTED|[EXTERNAL]|execute_anonymous_apex
07:45:33.31 (135567734)|USER_DEBUG|[9]|DEBUG|Limit Name: DailyAsyncApexExecutions
07:45:33.31 (135767388)|USER_DEBUG|[10]|DEBUG|Usage Value: 0
07:45:33.31 (135896547)|USER_DEBUG|[11]|DEBUG|Maximum Limit: 250000

2
  • I must have missed that when it came out. The last couple of years have been challenging, to say the least.
    – sfdcfox
    Dec 1, 2023 at 16:04
  • Thank you for this suggestion. I just introduced it into my solution and it's working like a charm! Dec 4, 2023 at 14:13
6

Note that future methods don't have their own limit. The limits are shared across schedulable, batchable, queueable, and future methods. There's no way to get this data directly in Apex, but the Limits API has the DailyAsyncApexExecutions property which will tell you how many calls you get per day, and how many remain. This requires a callout, though, so you can't find out this information in some contexts. One possible example would be a schedulable class. See the demo below.

Demo.

9
  • Thank you for the extra detail. With this information, it seems the best design would be to monitor this limit externally instead of trying to build a Limit callout into every async process. I think I'll propose building an external schedules job into our SF proxy that periodically checks the limits we care about and sends an email if they pass a certain threshold. Nov 30, 2023 at 14:03
  • Looks like I can't upvote you as my account is new. But thanks again for the help! Nov 30, 2023 at 14:04
  • 1
    @JacksonSardello You could write an hourly scheduled job to call the API and write the data somewhere or notify someone. Lots of options exist, just there's no call you can do directly in Apex. Don't worry about the upvote, I have plenty already. You'll get some reputation for accepting, and I've given you an upvote to get you closer to the right to upvote. Enjoy your stay here, and hopefully we'll see you around.
    – sfdcfox
    Nov 30, 2023 at 14:10
  • 1
    @PhilW they changed it some time ago. If the context user is active and not Automated Process, you can get the session Id without any hoops. Just call UserInfo.getSessionId as normal.
    – sfdcfox
    Nov 30, 2023 at 14:47
  • 2
    No need for a callout to get this, you can use the OrgLimits class directly - salesforce.stackexchange.com/a/413931/102 Dec 1, 2023 at 15:51

You must log in to answer this question.

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