You need to sign in to do that
Don't have an account?
How to catch Errors
Hi,
Below is my code. I pasted it from a Ajax api tool kit pdf available on the site
When i save the code, i gives me an error Object Expected. Please help
<apex:page >
<script src="../../soap/ajax/25.0/connection.js"
type="text/javascript"></script>
<script type="text/javascript">
window.onload = test;
function test(){
try{
var result = sforce.connection.query("Select Name, Id from User");
var records = result.getArray("records");
for (var i=0; i< records.length; i++) {
var record = records[i];
sforce.debug.log(record.Name + " -- " + record.Id);
} catch(error){
sforce.debug.log(error);
}
}
</script>
<div id="output"> </div>
</apex:page>
Thanks,
Venkat
Refer this :
http://www.salesforce.com/us/developer/docs/ajax/Content/sforce_api_ajax_errors.htm
Hi Venkat,
Please try the below code scripts, which displays details both in AJAX Debug shell and also in your visualforce page
<apex:page >
<script type="text/javascript">
var __sfdcSessionId = '{!GETSESSIONID()}';
</script>
<script src="/soap/ajax/18.0/connection.js" type="text/javascript"></script>
<script type="text/javascript">
window.onload = test;
function test()
{
try
{
var result = sforce.connection.query("Select Name, Id from User");
var str = '';
var records = result.getArray("records");
for (var i=0; i< records.length; i++)
{
var record = records[i];
str+=record.Name + " -- " + record.Id+ "<br>";
sforce.debug.log(record.Name + " -- " + record.Id);
}
output.innerHTML=str;
}
catch(error)
{
sforce.debug.log(error);
}
}
</script>
<div id="output"> </div>
</apex:page>
To know more about catching errors, please look into my blog post on Button Click Action Using AJAX Toolkit
Let me know if you face any issues still, else Mark this post as solved for the benefit of board readers.
Regards,
Bharathi
Salesforce For All