+ Start a Discussion
Mark Mulholland 3Mark Mulholland 3 

Can you retrieve the Async limits from a class?

Hello,

I can see there is a REST API that can be called so we can see where we are currently with all of the Salesforce limits. https://instance.salesforce.com/services/data/v37.0/limits/

We would like to be able to track the limits periodically using a trigger. Inside this trigger we would like to view the Daily Async Apex Executions, and do something if the number left is below a threshold

The only method that I can see of grabbing this number real time is with that REST API. Is there another way to grab that number? e.g. is there an object that I can query using SOQL? Alternatively, am I wrong in thinking it's impossible to grab the results from that REST API in a trigger?

I have searched for all resources on the topic and have come up blank. If someone could shine a light on this it would be greatly appreciated

Thanks
Mark
Best Answer chosen by Mark Mulholland 3
Raj VakatiRaj Vakati
Hi Mark,

You can use in the trigger ( Call as feature calls from the trigger ). See the code here for testing.  Please follow some standard best practices. 
String sessionId =UserInfo.getSessionId();
        
        Http h = new Http();
        HttpRequest req = new HttpRequest();        
        req.setMethod('GET');
        String val ='https://fscttt-dev-ed.my.salesforce.com/services/data/v37.0/limits' ;
        System.debug('===================>'+val);
        req.setEndpoint(val);
       
        req.setHeader('Authorization', 'OAuth ' + UserInfo.getSessionId());
        
        
        HttpResponse res = h.send(req);
        System.debug('res Status'+res.getStatus());
        String body = res.getBody();
        
        system.debug('=='+body);




 

All Answers

Raj VakatiRaj Vakati
Hi Mark,

You can use in the trigger ( Call as feature calls from the trigger ). See the code here for testing.  Please follow some standard best practices. 
String sessionId =UserInfo.getSessionId();
        
        Http h = new Http();
        HttpRequest req = new HttpRequest();        
        req.setMethod('GET');
        String val ='https://fscttt-dev-ed.my.salesforce.com/services/data/v37.0/limits' ;
        System.debug('===================>'+val);
        req.setEndpoint(val);
       
        req.setHeader('Authorization', 'OAuth ' + UserInfo.getSessionId());
        
        
        HttpResponse res = h.send(req);
        System.debug('res Status'+res.getStatus());
        String body = res.getBody();
        
        system.debug('=='+body);




 
This was selected as the best answer
Mark Mulholland 3Mark Mulholland 3
Hello Rajamohan,

Thank you, I was afraid that because it was a RES API call that I wouldn't be able to call it and view the response in the same trigger

I'll get to implementing this now

Mark
Harjeet Singh 13Harjeet Singh 13
Dear all, 

I am working on closecto same requiremnts. My need is send an alert to couple of users if daily limits of Async Apex Executions reaches a threshold of 70%.
If 70%of daily limit of Async Apex Execution Reaches then an alert notification should go to few users say User A and User B. 
Kindly help me on above requirements.
Any help will be greatly appreciated.

Many thanks in advance 

Thanks & Regards, 
Harjeet