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
ChrisparxChrisparx 

retrieve API Call Usage ?

Hello,

 

I'm simply looking for how to retrieve the current API calls of the org through Apex but don't find anything similar in the documentation. I know that we can find this information in the company profile but I would like to get this information in my trigger/class in order to prevent future call according to my own limit (some calls are very important while other could wait 24 hours). Does anyone know how to get this information ?

 

Thank you !

nicloznicloz

For that you need to create a future api call, I have the same issue months ago, below the code for the trigger and api call.

 

 

public class Your_APICall {

 
  //Future annotation to mark the method as async.
  @Future(callout=true)


//  String id, String name
public static void Your_APICall_Request () {

 

/*** process***/

 

}

}

 

 

trigger Event_Trigger on Event( after insert) {//in this case after insert, you have anotehr options, after before or insert, update.

   System.debug('Making future call');
    
    for (Event a : Trigger.new) {//table Event
    string contact_example =     a.Your_Variable;//get value of inserted fields
    Your_APICall.Your_APICall_Request();

    }

}

 

 

You can check in setup->monitor->apex work is the result if ok.

 

Best Regards

incuGuSincuGuS

Hey,

 

You can call methods of the object LIMIT to find out a lot of your current limits.

 

PAGE 294 : http://www.salesforce.com/us/developer/docs/apexcode/salesforce_apex_language_reference.pdf 

 

But i dont think you can find about that one.

ChrisparxChrisparx

 


nicloz wrote:

For that you need to create a future api call, I have the same issue months ago, below the code for the trigger and api call.

 

 

public class Your_APICall {

 
  //Future annotation to mark the method as async.
  @Future(callout=true)


//  String id, String name
public static void Your_APICall_Request () {

 

/*** process***/

 

}

}

 

 

trigger Event_Trigger on Event( after insert) {//in this case after insert, you have anotehr options, after before or insert, update.

   System.debug('Making future call');
    
    for (Event a : Trigger.new) {//table Event
    string contact_example =     a.Your_Variable;//get value of inserted fields
    Your_APICall.Your_APICall_Request();

    }

}

 

 

You can check in setup->monitor->apex work is the result if ok.

 

Best Regards


 

I'm not sure to understand how you can find the total number of API call by your method. I'm not doing directly an API call through @future but I use an external App (from App Exchange) doing lots of API call and there is no directly way to measure the total quantity of API call.

 

On another thread, someone gave the idea to make a request on the Company Information page and parsing the informations but doing a new API call in order to retrieve the number of API call does not make much sense...

 

 

ChrisparxChrisparx

 


incuGuS wrote:

Hey,

 

You can call methods of the object LIMIT to find out a lot of your current limits.

 

PAGE 294 : http://www.salesforce.com/us/developer/docs/apexcode/salesforce_apex_language_reference.pdf 

 

But i dont think you can find about that one.


Indeed, it's not possible. We can only find by this way the current limit of the current context variables. But we cannot find the current limit of a "24 hours limit" - no matter for API call, email, ... :(

 

incuGuSincuGuS

Hey,

 

As far as i know there is no way, but hey im no superman! :P

Let me know if you DO find out how to, it would be really helpful.

 

Gaston.