I am using one custom list button on one of the related list. But sometime when I click on this button I am getting the below error message:

A problem with the OnClick javascript for this button or link was encountered: Failed to execute send on 'XMLHttprequest': Failed to load 'https://cs21.salesforce.com/services/Soap/u/29.0'.

One thing to note here is that this error message is not coming all the time. But I need to fix this one. Below is my JS code for this button:

var RecordTypeQuery = "Select Id from RecordType where developername='Set_Up_Plan' and SObjectType='Activity_Plan__c'"; 
var recordtype= sforce.connection.query(RecordTypeQuery );
var records = recordtype.getArray("records");

Any help is much appreciated. Thanks in advance.

  • Before accessing the array (records[0]), should check if its not empty.
    – Raul
    Oct 25, 2016 at 7:53

1 Answer 1


Try this:

var records = sforce.connection.query("SELECT Id FROM RecordType WHERE developername = 'Set_Up_Plan' AND SObjectType = 'Activity_Plan__c'").getArray("records");
window.open("/{!$Setup.Org_Level_Settings__c.Activity_Plan_Prefix__c}/e?CF{!$Setup.Org_Level_Settings__c.Activity_Plan_ICP_Field_Id__c}={!JSENCODE(Account.Name)}&CF{!$Setup.Org_Level_Settings__c.Activity_Plan_ICP_Field_Id__c}_lkid={!Account.Id}&RecordType=" + records[0].Id + "&retURL={!Account.Id}", "_parent");

I believe it might be because you are using {!REQUIRESCRIPT("/soap/ajax/24.0/connection.js")} I believe you should update it to the latest version. Comment back if it doesn't work and I can have another look into this.

You can also cut down the amount of code you use by using .getArray("records"); to the end of your var.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .