+ Start a Discussion

Creating a custom "action" on a related list that executes code.

Hi SFDC Devs,

I am hoping someone here can help me. I have a set of custom objects to monitor inventory and quality control for my org. On the quality control (QC) record page, I have a custom button that executes some JS that updates all of the individual fields in that record to "Approve All" and thus pass that QC.

However, it is a hassle to have to click into each QC record to approve it, and would save our team some time if the record can be updated from the parent related list but clicking an action or link. I would like to ideally add an action next to delete or edit on the parent related list to "Approve All" that would update that record.

User-added image
I have tried creating an action but I don't think that is the right kind of action in this case. I know I can create a related list button that can execute apex to update all child records here, but I want to be able to specify which QC records get updated.

Can anyone point me in the right direction?

Thank you,
Abhijeet Anand 6Abhijeet Anand 6
You can create a List Button with Display Checkboxes (for Multi-Record Selection) enabled.
This will give you the option to submit the selected records for submission.

Thank you! In case anyone else was wondering, I was able to accomplish this will the following JavaScript button.

//get selected records to update
var records = {!GETRECORDIDS($ObjectType.Quality_Control__c)};

//create array
var newRecords = [];

//Check at least 1 record selected 
if(records.length<1) {
alert("Please choose at least one Quality Control record to Approve.");
} else {
//start for loop
try {
for (var n=0; n<records.length; n++){

var QC = new sforce.SObject("Quality_Control__c");
QC.id = records[n];

//Criteria to update
QC.USB_connector_is_not_damaged__c = "Approved"; 
QC.Software_recognizes_Probe__c = "Approved"; 
QC.Approved_Date__c = new Date(); 
if (QC.Sensor_Type__c = "Type1" ){ 
QC.Type1_Option__c = "Approved"; 
//Add new record to array
//Update records in array and refresh page
result = sforce.connection.update(newRecords);

//error catch
catch (e) {