Often we have a need to do simple updates to a list of Related records from the Parent Object. This can be accomplished by creating a simple AJAX Toolkit based function and attaching that to an SFDC Custom List button on the Related (Child) object.
- Create a custom button or link under Custom Buttons and Links on the Related/Child object
- Behavior should be “Execute Javascript”
- Type will be List Button
2. Copy and paste the following method, replacing the My_Parent_Object__c and Related_Child_Object__c with actual existing object names for your org
{!REQUIRESCRIPT(“/soap/ajax/26.0/connection.js”)}
var relatedRecsList = sforce.connection.query(“Select Id from Related_Child_Object__c where My_Parent_Object__c ='{!My_Parent_Object__c.Id}'”);
var relatedRecsArray =relatedRecsList .getArray(“records”);
if ( relatedRecsArray == null || relatedRecsArray[0] == null ) {
alert(“Nothing to update”);
} else {
var objList = [];
for (var recCount = 0; recCount < relatedRecsArray.length; recCount++) {
var aRelatedObj= new sforce.SObject(‘Related_Child_Object__c’);
aRelatedObj.Id = relatedRecsArray[recCount].Id;
aRelatedObj.Status__c = ‘UpdatedByAJAXTK’;
objList.push(aRelatedObj);
}
upObjs = sforce.connection.update (objList);
location.reload(true);
}
3. Put this List Button onto the right page layout of the My_Parent_Object__c