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
RichardC.ax220RichardC.ax220 

Ajax 8.0 campaign query fails with "Array element at 0 is null."

I have an S-Control running a Campaign query that worked fine until recently. Now the campaign query throws the error "Array element at 0 is null" when I query a campaign that has members.  The code is simple:
  function MemberIds(campaignID) {
this.count = 0;
var statusLine = document.getElementById("statusLine");
statusLine.innerHTML = "Getting Campaign members, please wait";
var MemberResultSet = sforce.connection.query("Select Id, ContactId, LeadId From CampaignMember where CampaignID = '"
+ campaignID + "'",
{onSuccess: handleMemberIdsQuery,
onFailure: handleQueryProblem,
source: {errorPrefix: "Campaign member query failed"
}
});
}
The handleQueryProblem function just pops an alert with the error:
  function handleQueryProblem(error, source) {
    alert(source.errorPrefix + " " + error);
    } 
It looks like the _invoke method in the API has lost an argument.
Has anyone else seen this problem and come up with a remedy?

 
 

cheenathcheenath
Your onFailure handler is getting called?

Or is this error in handleMemberIdsQuery() method?
RichardC.ax220RichardC.ax220
The error comes from the onFailure handler. It catches the error thrown from the sforce.Connection _invoke method. The S-Control also queries contacts and leads without this problem.
cheenathcheenath
I tried out your query and it seems to work fine for me (in my org) on FF.




RichardC.ax220RichardC.ax220
Cheenath,

Thanks for checking out the query. I tried a simple test case and it works as well. I hope that someone from Salesforce can tell us what  "Array element at 0 is null" means, so I can determine what to change in my S-Control to work around it.
cheenathcheenath
"Array element at 0 is null" means, you have passed in an array as arg to
_invoke and its first element is null. For query, the arg is just a string, so not
sure why you should be getting this.

BTW, have you extended String's prototype to add a push method to it?
Something like:

String.prototype.push = function() {}



RichardC.ax220RichardC.ax220
I solved this problem, and learned a couple of things in the process. My S-Control queries campaign members, then literally retrieves the leads and contacts from the member list. I had added Account.Name to the contact retrieve, but did not update the error handling that I used with the beta Ajax toolkit. I wrapped a "try {}" around the contact retrieve, and the exception catcher showed that the "Array element at 0 is null" error came from trying to retrieve Account. I changed Account.Name to AccountId in my contact retrieve list and the exception went away. So don't include relationships when retrieve'ing records.

The other lesson is that if you follow an asynchronous query with a synchronous call (such as my retrieve) that throws an error, and you don't catch the error, the onFailure handler from the asynchronous query will catch it.