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
pierrepierre 

AJAX async query calls success AND failure, error "invalid argument" number -2147024809

I'm doing a simple async query:
        sforce.connection.query(str,{onSuccess : nearbysuccess, onFailure : nearbyfailure, timeout: 40000});

the query (str) works, I tested it with the sforce explorer.

AND results are returned, the success callback is called BUT 'nearbyfailure' is ALSO called !!!!
the error returned has the following Javascript attributes:
    name: "Error"
    number : -2147024809
    description: "Invalid argument."
    message: "Invalid argument."

What is going on?
cheenathcheenath
Which version of Ajax toolkit? My tests seems to work fine.

Here is one:

 var result = sforce.connection.query("Select Name,Id from User", {
      onSuccess : success,
      onFailure : failure
    });

  function success(result) {
    var records = result.getArray("records");

    for (var i=0; i<records.length; i++) {
      var record = records[i];
      log(record.Name + " -- " + record.Id);
    }
  }

  function failure(error) {
    log("oops something went wrong " + error);
  }




pierrepierre
the latest version, as far as I know: <script src="/soap/ajax/12.0/connection.js" type="text/javascript"></script>
I know it works in most cases, I'm asking an explanation for the error I'm receiving.
cheenathcheenath
Well, without seeing your code it will be hard to tell. But my guess
will be that your onSuccess callback is throwing(causing) an error.



pierrepierre
It can't be: the succss callback takes the results as parameter, not the query error:
function nearbysuccess(aresult) {
    var it = new sforce.QueryResultIterator(aresult);
    while(it.hasNext()) {
        var record = it.next();
        if (record.type != "Account") {
             ......etc
It's only the failure callback that gets an error as parameter
function nearbyfailure(error) {
    alert("The query took too long to complete or an error was found: "+error.name+": "+error.message+" - "+error.description+  ....etc
would the error be thrown from the success callback, and somehow caught in the failure callback?? that wouldn't make any sense.. and that doesn't explain the error meaning.

If you really want it, the whole code is at http://docs.google.com/View?docid=dh2cnqn_9cfx2n8fp  .
cheenathcheenath
I mean, the success callback is throwing an error. You can wrap the callback in a try catch
and see if there is an error:

function nearbysuccess(aresult) {
  try {
 
      //your code here ...
  
  } catch(someerror) {
    alert("something went wrong " + someerror);
  }
}


pierrepierre
just tried it, you're right! The success callback throws an error that is caught (if not in the success function) by the failure callback.. not really intuitive...thank you for finding that... actually I just googled the error "invalid argument" (why didn't I do that in the first place? answer: because I was tired and frustrated last night when I wrote the post, shame on me) and it's clearly a javascript error.
I'll troubleshoot a bit more and will post the solution to close this post. thanks again.
cheenathcheenath
Cool, good luck.


pierrepierre
ok, found it, I was calling the standard javascript function setInterval like this:
        intervalid = setInterval(dorefresh(avariable),1000);
I switched to
        intervalid = setInterval("dorefresh()",1000);
and it works now.