I have a couple javascriptof JavaScript remoting functions used to count records and to display that count to the end user. The javascriptJavaScript remoting functions are on a visual forceVisualforce page, and the visual forceVisualforce page is embedded on a page layout of a custom object.
What is happening is that the javascipt remoting functions are supposed to count the number of records available after filters are set. However intermittently the user will receive the error “Unable to connect to server”.
I have a couple of javascriptJavaScript remoting functions are working against a custom object, and there are other remoting functions working on the Task object. These functions are doing nothing more than counting records in the system. The javascriptJavaScript remoting function counting records on the Task object are working more constistently than the javascriptJavaScript remoting functions counting records on the custom object.
I’m worried that this error may a result of the fact that the custom object is not indexed, and therefore counting records for that object may require more time than what is allowed for javasciptJavaScript remoting functions. If this is the case, should I do something to get the custom object indexed?
Also, I’m concerned that the “Unable to connect to server” error is a known bug, from what I have gathered on the forums. If this is the case is there a known fix?
Below is an example of the JavascriptJavaScript remoting function on the Task object, to count the number of task records for the given parameters. This function is failing some of the time, mostly in the morning when first logging into the system.
//Javascript Remoting Function
controllerExampleCounter.asyncReviewedClosed(String("{!Example_Custom_Setting_Validation__c.OwnerId}"), function(result, event)
{
if (event.status)
{
$("#reviewedClosed").text(addCommas(result));
}
else if (event.type === "exception")
{
$("#reviewedClosed").text("Error: " + event.message);
}
else
{
$("#reviewedClosed").text("Error: " + event.message);
}
}, {escape:true});
//Apex Function
@RemoteAction @ReadOnly
global static Integer asyncReviewedClosed(String owner_id)
{
Integer incomplete = 0;
try{
incomplete = [Select count()
From Task
Where RecordType.Name = 'Qualification Task' And
And CreatedById = :String.escapeSingleQuotes(owner_id)
And IsClosed = true
And CreatedDate = THIS_YEAR];
} catch(Exception e) {
}
return incomplete;
}