Find your content:

Search form

You are here

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?


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;
    result = sforce.connection.update(updateRecords); 

Attribution to: Steve Richardson

Possible Suggestion/Solution #1

I was facing the similar problem of 'INVALID_TYPE' when trying to update an array of Cases. After a long time I found out that the sforce.connection.update method only takes a SINGLE object at a time for updation. Since we were both passing an ARRAY, the call failed. Try passing only a single record and it should work fine.

There has to be something though to work with a collection.

Attribution to: Chetan Gupta

Possible Suggestion/Solution #2

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 ;))

Attribution to: eyescream

Possible Suggestion/Solution #3

Please update this line, you forget to add the id.
update_TeamMember.Id = records[a].id;

Attribution to: Monisha
This content is remixed from stackoverflow or stackexchange. Please visit

My Block Status

My Block Content