You need to sign in to do that
Don't have an account?
martin_wu
How to insert custom button with custom actions in list view
Hi all,
I am facing the following task: I have a standard list view of one of my custom objects. In this view, I would like to include a custom button that, when clicked, does the following:
- update a status field on all selected custom objects to a certain value
- take the user to another view which filters on the new value of the status field
Is this possible somehow?
Kind regards,
Martin
Use a custom list button and execute javascript using the Ajax Tookit..
As a sample for you - Here is code below that prompts the user for a status and mass updates the status on an object called PM_Req__c .
var ReqIdArr = {!GETRECORDIDS( $ObjectType.PM_Req__c )};
if (ReqIdArr == null || ReqIdArr.length == 0) { alert("Please select the requirements you wish to update.");
} else {
var Reqs = new Array();
var status_new = prompt("What is the new status for these requirements?");
for (var i = 0; i < ReqIdArr.length; i++) {
var req = new sforce.SObject("PM_Req__c");
//
req.Id = ReqIdArr[i];
// Next set the appropriate fields to update the
// requirement.
//
req.Status__c = status_new;
// // // req.Status__c = "Completed";
// // // optional update the stage or type - // req.Stage__c = "Closed - Completed";
// Finally add the record to our array.
//
Reqs.push(req);
}
// Now make the update API call in a try statement so we can
// catch any errors. Save the resulting array so we can also
// check for problems with individual records.
//
var callCompleted = false;
try {
var result = sforce.connection.update(Reqs);
callCompleted = true;
} catch(error) {
alert("Failed to update Requirements with error: " + error);
}
// Now check for problems with individual records.
//
if (callCompleted) {
for (var i = 0; i < result.length; i++) {
if (!result[i].getBoolean("success")) {
alert("Requirement (id='" + ReqIdArr[i] +
"') could not be updated with error: " +
result[i].errors);
}
}
// Finally, refresh the browser
//
window.location.reload(true);
}
}
All Answers
Use a custom list button and execute javascript using the Ajax Tookit..
As a sample for you - Here is code below that prompts the user for a status and mass updates the status on an object called PM_Req__c .
var ReqIdArr = {!GETRECORDIDS( $ObjectType.PM_Req__c )};
if (ReqIdArr == null || ReqIdArr.length == 0) { alert("Please select the requirements you wish to update.");
} else {
var Reqs = new Array();
var status_new = prompt("What is the new status for these requirements?");
for (var i = 0; i < ReqIdArr.length; i++) {
var req = new sforce.SObject("PM_Req__c");
//
req.Id = ReqIdArr[i];
// Next set the appropriate fields to update the
// requirement.
//
req.Status__c = status_new;
// // // req.Status__c = "Completed";
// // // optional update the stage or type - // req.Stage__c = "Closed - Completed";
// Finally add the record to our array.
//
Reqs.push(req);
}
// Now make the update API call in a try statement so we can
// catch any errors. Save the resulting array so we can also
// check for problems with individual records.
//
var callCompleted = false;
try {
var result = sforce.connection.update(Reqs);
callCompleted = true;
} catch(error) {
alert("Failed to update Requirements with error: " + error);
}
// Now check for problems with individual records.
//
if (callCompleted) {
for (var i = 0; i < result.length; i++) {
if (!result[i].getBoolean("success")) {
alert("Requirement (id='" + ReqIdArr[i] +
"') could not be updated with error: " +
result[i].errors);
}
}
// Finally, refresh the browser
//
window.location.reload(true);
}
}
Hi Mehmet,
Thanks a lot for the hint and the detailed code. I hadn't done any coding, yet, with the Ajax toolkit, so I didn't even think of using Javascript for the job.
Adding the custom buttons with the onclick JS has worked out perfectly fine. Thanks a million.
Cheers,
Martin