function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Sakthivel ThandavarayanSakthivel Thandavarayan 

Need help with javascript custom button to mass update & refresh list views

Hi there, The below script works well on case list views. however the problem is with the refresh, after the page refresh list view changes to something else. It not showing the selected list view, instead it's showing the first view or random(not sure). 

Is there way to update records, refresh the list view and select the same list view ? 


var records = {!GETRECORDIDS($ObjectType.Case)}; 
var newRecords = []; 

if (records[0] == null) 

alert("Please select at least one row") 


for (var n=0; n<records.length; n++) { 
var c = new sforce.SObject("Case"); = records[n]; 
c.Status = "Canceled"; 

result = sforce.connection.update(newRecords); 
William TranWilliam Tran
Hi, not sure I follow your issue.

But if Reload does not work for you, you can use Replace:

replace(url):Replace the current document with the one at the provided URL. 

so it would be

window.location.replace("YOUR URL");

YOUR URL can be relative to Salesforce server like


Sakthivel ThandavarayanSakthivel Thandavarayan

Reload is working fine. but after the reload, its going to random list view, not the one that was previously selected.

Consider I have 5 list views, and I'm in 3rd view now.
when I click the button, page reloads and list view selected now is not 3rd view. but 1st view. 

I want to reload the page and select the same list view where user left. Is that helps understanding my issue ? 

Add the following lines in the java script code, which will take the user to the same list view instead of going to the first list view option.
var listview = document.querySelectorAll('[name$="fcf"]')[0].value; 
Make sure to change '/001' into the prefix code of the object
how about 
window.location.href = "/500";
Sakthivel ThandavarayanSakthivel Thandavarayan
Karan & SQ

Both works. Still there is an issue without styling. Sorry for not mentioning it in the question as I'm not aware this will cause UI changes.

This button is placed in case list view and users using this button on (service)console app. After winter 16 release, console list view UI changed little bit compared to the actual list view(non console apps). 

After updating the script with the solutions you provided, it redirects properly to the same list view but UI changed. 

Before clicking the button 

User-added image


User-added image

Any idea what I'm missing ? 


Did you ever resolve this issue, we are encoutering it in our org as well, specificaly with the console the button works fine outside of that.

Sakthivel ThandavarayanSakthivel Thandavarayan
Unfortunately NO.... 
Parasuram Basi 4Parasuram Basi 4
Hi Sakthivel i am facing the same UI issue in list view mentioned above. Could you please share the solution if resolved
Addition to @Karanraj 's answer:
const listviewId = $('[name$="fcf"] option:checked').value;
window.location.replace('/001?fcf' + listviewId )