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
NM AdminNM Admin 

How to convert javascript List View button into lightning List View button?

Hello there,

I need suggestions to implement below requirement:
I have a js list button which is working for classic and classic service console. I want to make it lightning compatible so it can work in Lightning expereince, Lightning Service Console. 
Below is my js list button code:
sforce.connection.sessionId = '{!GETSESSIONID()}';
    var caseid ='{!Case.Id}';
    var records = {!GETRECORDIDS($ObjectType.Case)};
    var result = sforce.apex.execute("ClassNAme","checkUserPermissions",
    if(result == "") {
        if(records.length > 1) {
            alert('Please Select Only One Case !');
        else if(records.length < 1) {
            alert('Please Select A Case !');
        } else if(sforce.console.isInConsole()) {
            var url = '/apex/vfPagename?caseId='+records[0];
            var tabId = sforce.console.getEnclosingPrimaryTabId();
            sforce.console.openPrimaryTab(null,url, true);
        } else {
  '/apex/vfPagename?caseId='+records[0]); }
    else {

As solution I have created vf page and converted above code in visualforce in sript tag.It is opening the page as expected but the problem is when I click on the Cancel and Save button on the referred page in the code its not closing the current primary tab. Its showing blank page, the blank page is nothing but the vf page which I have created for converting js button code.

How can we achieve this requirement? any suggestions on this.

Welcome to your suggestions!

ANUTEJANUTEJ (Salesforce Developers) 
Hi Nilesh,

Can you try if the button is working by simply putting an alert statement and apart from this can you also check this below link that mentions regarding the conversion of javascript button to lightning.


I hope this helps, looking forward for hearing back from you.

NM AdminNM Admin
Hi @Anutej Thanks for quick quick response.

I already have alerts in my code. Which are workign for me btu when user navigating to the referred vf page then I'm getting this issue.
Any other way to acheive this?