+ Start a Discussion
ClintHegneyClintHegney 

AJAX Toolkit documentation?

I can't seem to find any documentation for the AJAX Toolkit. The documentation for .NET and Java is very good. Is there similar documentation for the AJAX Toolkit?
gsickalgsickal
Look here http://blog.sforce.com/sforce/general_api/index.html and scroll down to "Ajax Toolkit", then see the instructions for downloading the beta1 toolkit sample and docs.  The latest version is beta3.3 but you can still use the beta1.  If you want to use beta3, search the forum boards for "beta3" and you'll see where you can download it and samples etc or just go here: http://forums.sforce.com/sforce/board/message?board.id=scontrols&message.id=781
ClintHegneyClintHegney
I can't seem to get anything to return from a test query result. First I declared a global variable to hold HTML content.

var strHtml;

I have a page load function that creates initiates the AJAX session using merge variables. I have confirmed it is working because I can get the AJAX version and Session ID using those functions from the sforceClient object. Now I have the following functions that are called when a radio button is selected.

function ContactQuery() {

strHtml = "
Contact IDContact First NameContact Last Name
";

sforceClient.setBatchSize(20);
sforceClient.Query("Select Id, LastName, FirstName From Contact",QueryHandler,true);

strHtml = strHtml + "";

document.getElementById("divMain").innerHTML = strHtml;
}

function QueryHandler (qr) {
if (dltypeof(qr) == "SoapFault") {
alert(qr.toString());
} else {
if (qr.size > 0) {
for (var i=0;i var contact = qr.records[i];
strHtml = strHtml + "
" + contact.get("Id") + "
" +
"
" + contact.get("FirstName") + "
" +
"
" + contact.get("LastName") + "
";
}
}
}
}


I have also made sure that I added the script link required to init the AJAX toolkit. When the radiobutton is selected and calls the ContactQuery function, I get the header, but nothing else.

If I take these same two functions and use them in a page out side of Salesforce and use the sforceClient.Login function to create the session, then call the ContactQuery function in my page load function, then I get the data. What is the difference between using the Query in Salesforce vs out side of Salesforce that would be giving me these issues?
SteveBowerSteveBower
Hey Clint, You wrote:

"I have also made sure that I added the script link required to init the AJAX toolkit."

It sounds like this isn't coded properly. If that's the case, and you're not logged in, you might not be getting a SoapFault, but some other error code. Try alert(qr); regardless of the dltype, and see if that tells you anything.

Steve Bower

P.S. A previous posting from Dave tells you how to post code into these forums. Note, you must use IE for this as opposed to some other Browser. Here's the link to his posting.

http://forums.sforce.com/sforce/board/message?board.id=general_development&message.id=6327
ClintHegneyClintHegney
I don't under stand why this isn't working correctly. I have the following s-control defined, but it returns no records. I get the header row, but nothing else.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>

<head>
<title>Sforce AJAX Toolkit HelloWorld!</title>
<script src="https://www.sforce.com/ajax/beta3/sforceclient.js" type="text/javascript"></script>
</head>

<body>

<script language="javascript">
//<--
sforceClient.init("{!API_Session_ID}", "{!API_Enterprise_Server_URL_60}");

var qr = new Sforce.QueryResult();
qr = sforceClient.Query("Select Id, Name From Account");

document.write("<table border=\"1\"><tr><th>Acct Id</th><th>Acct Name</th></tr>");
for (var i=0;i<qr.records.length;i++) {
account = qr.records[i];
document.write("<tr><td>" + account.get("Id") + "</td>" +
"<td>" + account.get("Name") + "</td></tr>");
}
document.write("</table");
//-->
</script>

</body>

</html>

Now if I take this same file and substitute the sforceClient.init statement for an sforceClient.Login statement, I get a totally different problem all together. A script error is given here is the info.

Line: 685
Char: 4
Error: 'this.timerlog' is null or not an object
Code: 0
URL: <local hard drive path to file>

This error is obviously coming from the included script file as my code doesn't have 685 lines. What is going on here?
ClintHegneyClintHegney
I don't under stand why this isn't working correctly. I have the following s-control defined, but it returns no records. I get the header row, but nothing else.


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>

<head>
<title>Sforce AJAX Toolkit HelloWorld!</title>
<script src="https://www.sforce.com/ajax/beta3/sforceclient.js" type="text/javascript"></script>
</head>

<body>

<script language="javascript">
//<--
sforceClient.init("{!API_Session_ID}", "{!API_Enterprise_Server_URL_60}");

var qr = new Sforce.QueryResult();
qr = sforceClient.Query("Select Id, Name From Account");

document.write("<table border=\"1\"><tr><th>Acct Id</th><th>Acct Name</th></tr>");
for (var i=0;i<qr.records.length;i++) {
account = qr.records[i];
document.write("<tr><td>" + account.get("Id") + "</td>" +
"<td>" + account.get("Name") + "</td></tr>");
}
document.write("</table");
//-->
</script>

</body>

</html>


Now if I take this same file and substitute the sforceClient.init statement for an sforceClient.Login statement, I get a totally different problem all together. A script error is given here is the info.


Line: 685
Char: 4
Error: 'this.timerlog' is null or not an object
Code: 0
URL: <local hard drive path to file>


This error is obviously coming from the included script file as my code doesn't have 685 lines. What is going on here?
ClintHegneyClintHegney
I don't under stand why this isn't working correctly. I have the following s-control defined, but it returns no records. I get the header row, but nothing else. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <title>Sforce AJAX Toolkit HelloWorld!</title> <script src="https://www.sforce.com/ajax/beta3/sforceclient.js" type="text/javascript"></script> </head> <body> <script language="javascript"> //<-- sforceClient.init("{!API_Session_ID}", "{!API_Enterprise_Server_URL_60}"); var qr = new Sforce.QueryResult(); qr = sforceClient.Query("Select Id, Name From Account"); document.write("<table border=\"1\"><tr><th>Acct Id</th><th>Acct Name</th></tr>"); for (var i=0;i<qr.records.length;i++) { account = qr.records[i]; document.write("<tr><td>" + account.get("Id") + "</td>" + "<td>" + account.get("Name") + "</td></tr>"); } document.write("</table"); //--> </script> </body> </html> Now if I take this same file and substitute the sforceClient.init statement for an sforceClient.Login statement, I get a totally different problem all together. A script error is given here is the info. Line: 685 Char: 4 Error: 'this.timerlog' is null or not an object Code: 0 URL: [local hard drive path to file] This error is obviously coming from the included script file as my code doesn't have 685 lines. What is going on here?
ClintHegneyClintHegney
I added the following line to my script in the s-control.

alert(qr);

This is what I received in the alert.

size: 24
queryLocator: null
done: true
SOQL: Select Id, Name From Account
records:

So it looks like the query is working, why can't I iterate through it and get the records to print?
SteveBowerSteveBower
Clint, do this:


//sforceClient.init("{!API_Session_ID}", "{!API_Enterprise_Server_URL_60}");
sforceClient.init("{!API_Session_ID}", "{!API_Partner_Server_URL_70}");

The Ajax toolkit always uses the Partner interfaces. Then when you go to access an object of some kind, it issues (and caches) the results from a describe call about that object before trying to use it.

Good luck, Steve Bower.