You need to sign in to do that
Don't have an account?
StatBoyA
sforce.connection.query "uncaught exception"
I'm attempting a fairly simple S-Control including several uses of the API "query" function. My current working example is very simple and very similar to examples provided in the Ajax Toolkit Developer's Guide, but does NOT run.
As a relative novice, I suspect I'm overlooking something that would be obvious to the more experienced...
Here's an example of my code. This is cut back to the minimum JUST to illustrate the error:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<script src="/soap/ajax/12.0/connection.js"
type="text/javascript"></script>
<script type="text/javascript">
function initPage() {
var result = sforce.connection.query( "SELECT id, name from User");
}
</script>
</head>
<body onLoad="initPage();">
<h1>Test S-Control</h1>
</body>
</html>
Using FireFox with Firebug installed. Error message is "uncaught exception".
Firebug highlights "undefined" within it's more detailed output: Here's the detail provided by Firebug (WITHOUT the highlighting):
As a relative novice, I suspect I'm overlooking something that would be obvious to the more experienced...
Here's an example of my code. This is cut back to the minimum JUST to illustrate the error:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<script src="/soap/ajax/12.0/connection.js"
type="text/javascript"></script>
<script type="text/javascript">
function initPage() {
var result = sforce.connection.query( "SELECT id, name from User");
}
</script>
</head>
<body onLoad="initPage();">
<h1>Test S-Control</h1>
</body>
</html>
Using FireFox with Firebug installed. Error message is "uncaught exception".
Firebug highlights "undefined" within it's more detailed output: Here's the detail provided by Firebug (WITHOUT the highlighting):
uncaught exception: [Exception... "Unexpected error" nsresult: "0x8000ffff (NS_ERROR_UNEXPECTED)" location: "JS frame :: https://na2.salesforce.com/soap/ajax/12.0/connection.js :: anonymous :: line 580" data: no]newConnection()connection.js (line 578)send("<se:Envelope xmlns:se="http://schemas.xmlsoap.org/soap/envelope/"><se:Header xmlns:sfns="urn:partner...", Object isAsync=false isArray=false, false, undefined)connection.js (line 588)send("/services/Soap/u/12.0", <se:Envelope xmlns:se="http://schemas.xmlsoap.org/soap/envelope/"><se:Header xmlns:sfns="urn:partner.soap.sforce.com"><sfns:SessionHeader><sessionId>4c0200D300000006KvS!ARYAQLrdlONOAKEAjOpn20vcAcxH_mhEpNFnYE428hQ2EUv5bUHB5atIn1p39uWKGcPPINcCLQWPG4tJXPfOsS3ixLCKZuF7</sessionId></sfns:SessionHeader></se:Header><se:Body><query xmlns="urn:partner.soap.sforce.com" xmlns:ns1="sobject.partner.soap.sforce.com"><queryString>SELECT id, name from User</queryString></query></se:Body></se:Envelope>, false, undefined)connection.js (line 1017)_invoke("query", [Object name=queryString value=SELECT id, name from User], false, undefined, [Object ns=urn:partner.soap.sforce.com, Object ns=sobject.partner.soap.sforce.com prefix=ns1], "/services/Soap/u/12.0", "urn:partner.soap.sforce.com", "sobject.partner.soap.sforce.com")connection.js (line 1597)invoke("query", [Object name=queryString value=SELECT id, name from User], false, undefined)connection.js (line 1536)initPage()servlet.Integrati... (line 12)
******************** WORKING **********************
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<script src="/soap/ajax/12.0/connection.js"
type="text/javascript"></script>
<script type="text/javascript">
function initPage() {
//WORKING
var result = sforce.connection.query( "SELECT Id, Name FROM User");
var records = result.getArray("records");
document.writeln("<br /> SOQL entered as literal to 'query' call<br />");
document.writeln(records.length + " records returned <br />");
document.writeln("result.size = " + result.size + "<br />");
for (var i=0; i< records.length; i++) {
var curRec = records[i];
document.writeln(" rec " + i + " " + curRec.Name + "<br />");
}
}
</script>
</head>
<body onLoad="initPage();">
<h1>Test S-Control</h1>
</body>
</html>
************** NOT WORKING *************************
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<script src="/soap/ajax/12.0/connection.js"
type="text/javascript"></script>
<script type="text/javascript">
function initPage() {
//NOT WORKING
var qryString = "SELECT Id, " +
"Name " +
"FROM User";
document.writeln("<br />qryString: " + qryString + "<br />");
document.writeln("String(qryString): " + String(qryString) + "<br />");
var result = sforce.connection.query( qryString );
//var result = sforce.connection.query( String( qryString ));
var records = result.getArray("records");
document.writeln(records.length + " records returned <br />");
for (var i=0; i< records.length; i++) {
var curRec = records[i];
document.writeln(" rec " + i + " " + curRec.Name + "<br />");
}
}
</script>
</head>
<body onLoad="initPage();">
<h1>Test S-Control</h1>
</body>
</html>
Now I notice that EVERY example I look at using the "query" API call in both the Ajax Toolkit Developer's Guide and the Force.com Web Services API Developer's Guide provide the query string as a LITERAL. I just assumed that I construct a query string using a variable and feed the value to the 'query' method using that variable... Was I wrong?
For those of you who are well beyond this type of struggling... thanks in advance for any input offered...
Looks like a type conversion problem.
Actually, I thought of that possibility. However, I attempted using the "String()" function to ensure a string was being provided.
I believe I also tried ".toString", but it's all getting a bit fuzzy at this point.
I'll give it a try and see what happens. It's always possible I made an error during my earlier attempt.
Thanks for the suggestion
// ********************** NOT WORKING **********************************
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<script src="/soap/ajax/12.0/connection.js"
type="text/javascript"></script>
<script type="text/javascript">
function initPage() {
//NOT WORKING
var qryString = "SELECT Id, " +
"Name " +
"FROM User";
document.writeln("<br />qryString: " + qryString + "<br />");
document.writeln("String(qryString): " + String(qryString) + "<br />");
//var result = sforce.connection.query( qryString );
var result = sforce.connection.query( qryString.toString );
var records = result.getArray("records");
document.writeln(records.length + " records returned <br />");
for (var i=0; i< records.length; i++) {
var curRec = records[i];
document.writeln(" rec " + i + " " + curRec.Name + "<br />");
}
}
</script>
</head>
<body onLoad="initPage();">
<h1>Test S-Control</h1>
</body>
</html>
//********************* NOT WORKING *******************************
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<script src="/soap/ajax/12.0/connection.js"
type="text/javascript"></script>
<script type="text/javascript">
function initPage() {
//NOT WORKING
var qryString = "SELECT Id, " +
"Name " +
"FROM User";
document.writeln("<br />qryString: " + qryString + "<br />");
document.writeln("String(qryString): " + String(qryString) + "<br />");
document.writeln("qryString.toString(): " + qryString.toString() + "<br />");
//var result = sforce.connection.query( qryString );
var result = sforce.connection.query( qryString.toString() );
var records = result.getArray("records");
document.writeln(records.length + " records returned <br />");
//Display summary of returned recs for confirmation
for (var i=0; i< records.length; i++) {
var curRec = records[i];
document.writeln(" rec " + i + " " + curRec.Name + "<br />");
}
}
</script>
</head>
<body onLoad="initPage();">
<h1>Test S-Control</h1>
</body>
</html>
I only scanned the FireBug output briefly, but it looks GENERALLY similar to the description copied into my starting message in this thread. Naturally, the session id and similar info differs...
Thanks for reporting your success back for me.
I guess this makes it clear that the problem is related to something about my SF Developer installation OR the "production" installation of SF I'm working on. This at LEAST gives me some clues about where to be looking...