Monday, April 9, 2012

Refresh Record on click Custom Button or Link in Force.com (Salesforce) using Javascript

Create the custom button or link on your object and assign the behavior "Execute Javascript".

Within your Javascript after your implementation (let's say post updating the record from your javascript code) you can reload the active window which would in turn refresh the record with the latest content for it.

You can use the following to trigger the window reload.

// Updating the record
var result = sforce.connection.update([wi]); 
// Refresh window to refresh and show updated record
if (result[0].getBoolean("success")) { 
window.location.reload();
}