1

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:

{!REQUIRESCRIPT("/soap/ajax/24.0/connection.js")} 
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");
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");

Any help is much appreciated. Thanks in advance.

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

Try this:

{!REQUIRESCRIPT("/soap/ajax/33.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/33.0/apex.js")}
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.