1

Have any of you figured out the usage of API Limits (per 24-hour interval) when using Apex back into the org?

Let's say something that uses System.URL.getOrgDomainUrl().toExternalForm() as domain to call an SFDC REST resource not yet available in Apex, using standard Apex HttpRequest (some resources from Connect REST API for instance).

I have tried to use the report "API Calls Made Within Last 7 Days", but I cannot find a definitive answer.

1

1 Answer 1

1

You can get the current usage with:

HttpRequest req = new HttpRequest();
req.setEndpoint(new Url(Url.getSalesforceBaseUrl(), '/services/data/v55.0/limits').toExternalForm());
req.setMethod('GET');
req.setHeader('Authorization', 'OAuth '+UserInfo.getSessionId());
HttpResponse res = new Http().send(req);
Map<String, Object> values = (Map<String, Object>)JSON.deserializeUntyped(res.getBody());
Map<String, Object> dailyLimits = (Map<String, Object>)values.get('DailyApiRequests');
Integer maxCallPerDay = (Integer)dailyLimits.get('Max');
Integer remainingCallsForToday = (Integer)dailyLimits.get('Remaining');
System.debug(remainingCallsForToday);

You can see the full list of available properties in the documentation.

3
  • Great reminder, thanks sfdcfox. So, the one million dollar question is: does this call to limits API counts into the limits? I will test but I guess so. Oct 4, 2022 at 18:02
  • 1
    @JefersonChaves unfortunately, yes. Make sure you use it sparingly.
    – sfdcfox
    Oct 4, 2022 at 20:38
  • You are awesome sfdcfox! Oct 5, 2022 at 8:47

You must log in to answer this question.

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