function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Harjeet Singh 13Harjeet Singh 13 

Notification alert for Async Apex Execution Limits

I want to send an alert notification when overall organisation Async Apex Execution limit reached 70%of total limit(24hrs API Limit). Say if limit is 2500 and if system already exhausted 1750 of daily Async Apex Limit out of 2500 then any alert should be send to few persons notifying that your organisation limit of Async Apex Executions have reached 70% threshold.

I have done few research on the same but didn't get anything concrete. I saw blogs/documentation stating about Limit class and Limit methods but those are having limit method for future but no where I get any thing related to Async Apex Exceution Limits. In Limit Class I saw there are 2 mthods 'getAsyncCalls()' and 'getLimitAsyncCalls()' but both are related reserved for future use.
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_limits.htm#apex_System_limits_getAsyncCalls

Kindly help me.

Any help will be greatly appreciated.

Many thanks in advance

Thanks & Regards,
Harjeet
Raj VakatiRaj Vakati
Make an API call to standard salesforce rest resource /services/data/v41.0/limits/ by using callouts to get the details 

Please refer this link 

https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/resources_limits.htm
 
Http h = new Http();
        HttpRequest httpReq = new HttpRequest();
        httpReq.setMethod('GET');
        httpReq.setEndpoint('callout:REST_API1/services/data/v37.0/limits/');
        HttpResponse res = h.send(httpReq);
        System.debug('res'+res);
        Map<String, Object> root = (Map<String, Object>)JSON.deserializeUntyped(res.getBody());
        System.debug('root'+root.keySet());
        for(String keys : root.keySet()){
            Map<String, Object> i = (Map<String, Object>)root.get(keys);
            Decimal percentage = Decimal.valueOf(String.valueOf(i.get('Remaining')))*100 /  Decimal.valueOf(String.valueOf(i.get('Max')));
            LimitsWrapper wrap = new LimitsWrapper();
            wrap.groupName = keys ; 
            wrap.usedPercentage = percentage.setScale(2) ; 
            warpperlist.add(wrap);
        }



 
Harjeet Singh 13Harjeet Singh 13
Dear Raj,

Thanks for your quick response. I already read the link which you have shared. But I am unsure about the design pattern needs to be followed. I am nit sure how to start the same. It would be a great help if you can explain a bit about the design which I should follow from starting. It could be like 
1. Callout to rest resource--How to make and how to start
2. Once receive details athen how can notify couple of peoples/users/folks

I may be asking very basic questions but I am really blank on this.

Kindly help me.

Any help will be greatly appreciated.

Many thanks in advance

Thanks & Regards,
Harjeet