[SalesForce] Update a checkbox on all records in a related list from a related list button with JavaScript

I need to allow a user to select one or more records from a related list and click a button on that related list that sets a checkbox to true on each selected record.

I have prepared the following javascript in a custom button and displayed checkboxes in the related list.

Currently, when the button is clicked, the records are not updating and the checkboxes are not getting set.

Custom object: FF__Team_Member_c
Custom field: Checkbox on FF
_Team_Member__c : Send_Email_to_Team_Member__c

Any thoughts?

{!REQUIRESCRIPT("/soap/ajax/20.0/connection.js")} 

var records = {!GETRECORDIDS($ObjectType.FF__Team_Member__c)}; 
var updateRecords = []; 

if (records[0] == null) { 
    alert("Please select at least one record to update.");  
} else { 
    for (var a=0; a<records.length; a++) { 
        var update_TeamMember = new sforce.SObject("FF__Team_Member__c");
        update_TeamMember.Id = records[a];
        update_TeamMember.Send_Email_to_Team_Member__c = true;
        updateRecords.push(update_TeamMember);
    }
    result = sforce.connection.update(updateRecords); 
location.reload(true);
}

Best Answer

This should work, I can think only of couple problems here:

  1. Are you on iPhone/iPad? There were some known bugs with GETRECORDIDS not working properly on iSafari (regular Safari seems to be fine).
  2. Are you sure the object name is typed correctly? It has 2 underscores = FF must be a managed package? Is current user allowed to edit them etc etc? (even if you're sysadmin objects might appear invisible - not returned in describe results if Profile permissions aren't set)
  3. Any validation rules /trigger-based checks you might be hitting over there? You're swallowing all results which might contain errors. Perform simple alert(results); or maybe sth like this:

for(var i = 0; i < results.length; ++i){
    if (result[i].getBoolean("success")) {
        log("record with id " + result[i].id + " updated");
    } else {
        log("failed to update record " + result[i]);
    }
}

(inspect the browsers JS console afterwards or replace log with alert but then make sure to not tick too many checkboxes ;))