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

Problem with List button onclick Javascript


I created a List Button :

List Button code :

var recordsToTransfer = {!GetRecordIds($ObjectType.Order__c)}

function init(){
if(recordsToTransfer.length < 1){
alert(" Please Select a value") ;

else if (!document.elementsAddedToPage)
for(var i=0; i < recordsToTransfer.length ; i++) {
function Edit(OrderID){
var Edit = new sforce.SObject("Order__c");
Edit.Id = OrderID;
Edit.Order_Status__c = "Ready";
var result = sforce.connection.update([Edit]);


This code will change the Status of the selected Orders. It works fine But a few times (in I.E. 7.0)  I've got a weird error :

Something like : 'Error On Click Javascript  Sforce is not defined ';

Please, can someone help me on this ? I don't understand this error. (Apparently It's only for some no Admin Profile users... and always in I.E. 7.0 even if I had that error once in firefox in admin profile :s but once I refreshed it was ok) I tryed already to update I.E, but does not work!

Thank you in advance for your help; this is really very important ...


Message Edited by Mig on 02-12-2008 01:13 PM
I tryed to add this :


I have no idea if it will change something ...

Hi Mig,

You need to add first connection.js and then function.js also check which js file version u r using.
Hello Mig,

You should only need to include one of the RequiredScript tags since that is what determines what commands you use. If you use the first code below it will give you all of the recent API commands. I also included an Execute JavaScript button code to update the Contact addresses as an example.



var getContacts = sforce.connection.query("Select c.Id From Contact c WHERE c.AccountId = '{!Account.Id}'"); 
var contactRecords = getContacts.getArray("records"); 
var error = false; 

if(contactRecords.length > 0){ 
var getAccAddress = sforce.connection.query("Select a.BillingStreet, a.BillingState, a.BillingPostalCode, a.BillingCountry, a.BillingCity From Account a WHERE a.Id = '{!Account.Id}'"); 
var accRecords = getAccAddress.getArray("records"); 

if(accRecords.length > 0){ 
var thisAcc = accRecords[0]; 
var billStreet = thisAcc.BillingStreet; 
var billState = thisAcc.BillingState; 
var billCode = thisAcc.BillingPostalCode; 
var billCountry = thisAcc.BillingCountry; 
var billCity = thisAcc.BillingCity; 

// Update contact addresses 

thisContact = contactRecords[i]; 
thisContact.MailingStreet = billStreet; 
thisContact.MailingState = billState; 
thisContact.MailingPostalCode = billCode; 
thisContact.MailingCountry = billCountry; 
thisContact.MailingCity = billCity; 
contactRecords[i] = thisContact; 
} // END for loop populating contact information 

// Save updated Contacts 

var saveResults = sforce.connection.update(contactRecords); 


if(saveResults[i].success == 'false'){ 
alert(saveResults[i].errors.message + " " + saveResults[i].errors.statusCode); 
error = true; 
} // END if statement to notify if error occurs 

} // END for loop 

// Notify user updates completed 

alert('Contacts Updated'); 
} // END user notification 

} else { 
alert('No Contacts associated or an error has occured, please verify and contact administrator'); 
} // END else of the if statement. If there was an Account returned from the query 

}// END if statement 

 Forgive the formatting of the code, I don't have the development tool to get the original code here.

Please let me know if you have questions.
Tkx both for your reply =)
Indeed it works fine !