• pawel999
  • NEWBIE
  • 0 Points
  • Member since 2009

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 6
    Replies

I've created a custom class with a webservice method which is parsing the 'System Overwiev' page and gets the Current Api Usage.
I've integrated it in my application and method returns what I expect and runs OK most of the time.
Unfortunately, from time to time I get an SoapFaultException. I decided to dig into it, and debug the whole method which looks like this:

global class ApiCallCheck
{

// Get current number of API requests used right now.
WebService static String getApiCurrent()
{
System.debug('===== Api Call Check =======');
PageReference pr = new PageReference('/setup/systemOverview.apexp');
pr.setRedirect(false);
String result = pr.getContent().toString();
System.debug(result);
// Find the label for API requests.
Integer start_index = result.indexOf('<div class="num" id="usage_block_api_num_1"><span class="textOnly">', 1) + 67;
System.debug(start_index);
// Find the first space afterward; this is the current API requests.
Integer end_index = result.indexOf('</span>', start_index);
System.debug(end_index);
result = result.substring(start_index, end_index);
System.debug(result);
// Clean up the result.
System.debug('===== Api Call Check END =======');
return result;

}

}

 



And that is what I get in logs when error pops up:

 

16.0 APEX_CODE,DEBUG;APEX_PROFILING,INFO;CALLOUT,INFO;DB,INFO;SYSTEM,DEBUG;VALIDATION,INFO;VISUALFORCE,INFO;WORKFLOW,INFO
02:18:09.017 (17377000)|EXECUTION_STARTED
02:18:09.017 (17462000)|CODE_UNIT_STARTED|[EXTERNAL]|01pP00000009YTU|ApiCallCheck.getApiCurrent
02:18:09.018 (18957000)|METHOD_ENTRY|[1]|01pP00000009YTU|ApiCallCheck.ApiCallCheck()
02:18:09.018 (18988000)|METHOD_EXIT|[1]|ApiCallCheck
02:18:09.019 (19226000)|SYSTEM_METHOD_ENTRY|[7]|System.debug(ANY)
02:18:09.019 (19301000)|USER_DEBUG|[7]|DEBUG|===== Api Call Check =======
02:18:09.019 (19336000)|SYSTEM_METHOD_EXIT|[7]|System.debug(ANY)
02:18:09.019 (19487000)|SYSTEM_METHOD_ENTRY|[9]|System.PageReference.setRedirect(Boolean)
02:18:09.019 (19578000)|SYSTEM_METHOD_EXIT|[9]|System.PageReference.setRedirect(Boolean)
02:18:09.019 (19630000)|SYSTEM_METHOD_ENTRY|[10]|System.PageReference.getContent()
02:18:09.019 (19916000)|FATAL_ERROR|Internal Salesforce.com Error
02:18:09.859 (19947000)|CUMULATIVE_LIMIT_USAGE
02:18:09.859|LIMIT_USAGE_FOR_NS|(default)|
Number of SOQL queries: 0 out of 100
Number of query rows: 0 out of 50000
Number of SOSL queries: 0 out of 20
Number of DML statements: 0 out of 150
Number of DML rows: 0 out of 10000
Number of code statements: 4 out of 200000
Maximum heap size: 0 out of 6000000
Number of callouts: 0 out of 10
Number of Email Invocations: 0 out of 10
Number of fields describes: 0 out of 100
Number of record type describes: 0 out of 100
Number of child relationships describes: 0 out of 100
Number of picklist describes: 0 out of 100
Number of future calls: 0 out of 10

02:18:09.859|CUMULATIVE_LIMIT_USAGE_END

02:18:09.020 (20010000)|CODE_UNIT_FINISHED|ApiCallCheck.getApiCurrent
02:18:09.020 (20027000)|EXECUTION_FINISHED

 

Request - Response:

WSC: Creating a new connection to https://cs4.salesforce.com/services/Soap/class/ApiCallCheck Proxy = DIRECT username null
------------ Request start   ----------
<?xml version="1.0" encoding="UTF-8"?><env:Envelope
   xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
 <env:Header>
  <SessionHeader
     xmlns="http://soap.sforce.com/schemas/class/ApiCallCheck">
   <sessionId>00DP00000007FQM!ARMAQNcaWbnCXvb10Tn13NObpJ.dLPWXug25lCn4QSmEBvgz25IkhdHTz5TXSWRp4Y8Z19IghDnUFQ9ueJM61JqRDmz7BFjD</sessionId>
  </SessionHeader>
 </env:Header>
 <env:Body>
  <m:getApiCurrent
     xmlns:m="http://soap.sforce.com/schemas/class/ApiCallCheck" />
 </env:Body>
</env:Envelope>
------------ Request end   ----------
null=[HTTP/1.1 500 Server Error]
Transfer-Encoding=[chunked]
Date=[Wed, 26 Jun 2013 08:54:40 GMT]
Content-Type=[text/xml;charset=UTF-8]
------------ Response start ----------
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
  <soapenv:Body>
    <soapenv:Fault>
      <faultcode>soapenv:Server</faultcode>
      <faultstring>
      </faultstring>
    </soapenv:Fault>
  </soapenv:Body>
</soapenv:Envelope>
------------ Response end   ----------

 

This looks like some problem with getContent() method that probably lies on Salesforce side (cant imagine what can be wrong).
Can anyone tell me how can I get around this problem? Some substitute for getContent() method? thanks for any help.

I have an apex webservice. Long story short its extracting (parsing) some data from system overview page for my account (current api limit). The method is called roughly every 10 minutes (I'm using sandbox).

To make it work I've walk through all steps necessarry. I've created an apex class, then generated wsdls and integrate it with my java application.

Apex class:

 

global class ApiCallCheck
{
   
   // Get current number of API requests used right now.
   WebService static String getApiCurrent()
   {
  
      PageReference pr = new PageReference('/setup/systemOverview.apexp?setupid=SystemOverview&retURL=%2Fui%2Fsetup%2FSetup');
      pr.setRedirect(false);
      String result = pr.getContent().toString();
      // Find the label for API requests.
      Integer start_index = result.indexOf('<div class="num" id="usage_block_api_num_1"><span class="textOnly">', 1) + 67;
      // Find the first space afterward; this is the current API requests. 
      Integer end_index = result.indexOf('</span>', start_index); 
      result = result.substring(start_index, end_index);
      // Clean up the result.
      return result;
   }

}

 

 

I'm logging to salesforce, then creating soap connection with session header I get from loginResult.

 

loginResult = binding.login("un", "pw");  
connection = Connector.newConnection("","");
connection.setSessionHeader(loginResult.getSessionId());

 

 

Everything worked fine for about 20 hours. There weren't any other apps accessing the webservice in the same time. After that time I'm getting the following error every time I'm calling the method:

 

com.sforce.ws.SoapFaultException:
at com.sforce.ws.transport.SoapConnection.createException(SoapConnection.java:204)
at com.sforce.ws.transport.SoapConnection.receive(SoapConnection.java:148)
at com.sforce.ws.transport.SoapConnection.send(SoapConnection.java:110)
at com.sforce.soap.ApiCallCheck.SoapConnection.getApiCurrent(SoapConnection.java:177)
at com.xformation.salesassistant.soap.salesforce.apiusage.ApiUsage.getResultFromSalesForce(ApiUsage.java:33)
at com.xformation.salesassistant.soap.salesforce.apiusage.ApiUsage.getApiRequestCount(ApiUsage.java:17)
at com.xformation.salesassistant.soap.salesforce.SalesForceBinding.getApiRequestCount(SalesForceBinding.java:439)
at com.xformation.salesassistant.soap.salesforce.SalesForceFacade.getApiRequestCount(SalesForceFacade.java:226)
at com.xformation.salesassistant.job.NotificationCreator.getApiRequestCount(NotificationCreator.java:192)
at com.xformation.salesassistant.job.NotificationCreator.validateApiRequestLimit(NotificationCreator.java:248)
at com.xformation.salesassistant.job.NotificationCreator.doExecute(NotificationCreator.java:49)
at com.xformation.salesassistant.job.JobAbstract.execute(JobAbstract.java:22)
at org.quartz.core.JobRunShell.run(JobRunShell.java:213)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:557)

 Note there is no message bound to that exception.

 

Here is how request - response looks like:

 

WSC: Creating a new connection to https://cs4.salesforce.com/services/Soap/class/ApiCallCheck Proxy = DIRECT username null
------------ Request start   ----------
<?xml version="1.0" encoding="UTF-8"?><env:Envelope
   xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
 <env:Header>
  <SessionHeader
     xmlns="http://soap.sforce.com/schemas/class/ApiCallCheck">
   <sessionId>00DP00000007FQM!ARMAQNcaWbnCXvb10Tn13NObpJ.dLPWXug25lCn4QSmEBvgz25IkhdHTz5TXSWRp4Y8Z19IghDnUFQ9ueJM61JqRDmz7BFjD</sessionId>
  </SessionHeader>
 </env:Header>
 <env:Body>
  <m:getApiCurrent
     xmlns:m="http://soap.sforce.com/schemas/class/ApiCallCheck" />
 </env:Body>
</env:Envelope>
------------ Request end   ----------
null=[HTTP/1.1 500 Server Error]
Transfer-Encoding=[chunked]
Date=[Wed, 26 Jun 2013 08:54:40 GMT]
Content-Type=[text/xml;charset=UTF-8]
------------ Response start ----------
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
  <soapenv:Body>
    <soapenv:Fault>
      <faultcode>soapenv:Server</faultcode>
      <faultstring>
      </faultstring>
    </soapenv:Fault>
  </soapenv:Body>
</soapenv:Envelope>
------------ Response end   ----------

 

I have no idea what is wrong. I'm logged properly, and can call 'standard' methods. I can't find any info about that messageless exception.

Are the ANY limits I don't know about? Because this looks like I've reached some, but I've found some apex limits and they don't seem to concern me.

What am I missing?

As I said, everything worked fine for some time, so I don't think I could have screwed anything in the way I'm connecting to the webservice.

Note that since the error appeared for the first time, it is continuosly appearing I'm getting the same error again and agian.

 

EDIT: It worked again for some time. But now its throwing the exception mentioned above again.

Please help.

 

I have a problem with logout() method in SoapBindingStub.

 

I have a logic responsible for retrying salesforce method invocation (f.e query) when it throws an exception calling it first time (session ended, wrong token etc).

It works like this: call to sf method > check if method didnt throw exception >  try to call again if it did, then try again (2 times, then throw 'final' exception).

 

Now, I'm testing session expiring by logging out of salesforce (binding.logout()).

The problem is it seems like logout method did not log me out of salesforce IMMEDIATELY sometimes - it seems there is a RANDOM delay after calling the logout() and being actually logged out, but im always logged out at some point.

How do I know that? If I call out a method after logout sometimes it works like everything was fine (not logged out, which is wrong), but in the next assertion, f.e invocation of another retriable method, it detects the session is indeed invalid and retries there, which seems wrong for me, because I'd expect it to either not work at all or work without delay at the first retriable method invocation.

 

Does anyone know what could be the problem/possible solution? I spent an eternity trying to figure this out and I have no clue. It just seems to be random. Thank you for any help.

Hello! Is there a way of getting the current apli calls count (the one that is under system overview) by a salesforce query?  I know I can check it at any point by accessing my account, or check last 7 days, but that is not what I'm interested in and not what I'm asking for.  Let's say I want to be able to get that number every time I am using a part of my code, or just to have more detailed statistics created in real time f.e ever 15 minutes or so.

Hello all,

 

I am attempting to make a connection to our SandBox environment programatically with the API.


When I connected to our production environment, I did so using PERL as follows:


use WWW::Salesforce::Simple;

my $sforce = WWW::Salesforce::Simple->new(
    'username' => $user,
    'password' => $pass,
);



the wsdl.jsp file contains the line:

<port binding="tns:SoapBinding" name="Soap">
   <soap:address location="https://www.salesforce.com/services/Soap/c/15.0"/>
</port>

This worked fine.


However, what I want to do is connect to the SandBox environment.


I appended  ".<our sandbox name>"   to the end of the username.
(I was able to login successfully with this username and it's password at https://test.salesforce.com with

a Web browser so I know my credentials are correct).


In the wsdl.jsp file I tried both the above snippet as well as:



<port binding="tns:SoapBinding" name="Soap">
   <soap:address location="https://test.salesforce.com/services/Soap/c/15.0"/>
</port>


My Perl script that I am using to try to connect is:

#!/usr/bin/perl -w
use strict;

use WWW::Salesforce::Simple;


my $user = '<the username I successfully used on Web browser with sandbox name appended>';
my $pass = '<our password>';

my $sforce = WWW::Salesforce::Simple->new(
    'username' => $user,
    'password' => $pass,
);


print "done\n";




When I run this script I get the following error:

INVALID_LOGIN: Invalid username or password or locked out. at ./connect.pl line 10

 

Not sure how to resolve this. Any assistance with this would be greatly appreciated.

 

 

Regards,

 

RanS

  • February 26, 2009
  • Like
  • 0