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
SFDC93 SfSFDC93 Sf 

Why VF page is not closing after clicking a button in lightening

Hi All,
I have an issue with a list button on contact (Custom object) of related list of case. When I click that custom button (vf page will open), it opens a new tab/window in lightening console (Works perfect in classic console). But it is opening in two new tabs. I dont know why? 

Expected functionlaity/What I want exactly is: 
When you click that button, opens vf page as new tab/window. There are two lookup field to case and contact(Custom field). And this contact (custom field) prepopulated with the contact number/id. Then you have chance to attach a case to it. once you attach any case and save, it is opening in new tab with updated/attached case to it. Now, am seeing 3 tabs. two tabs has same edit vf page and 3rd tab is details page of contact. 

See below, 
3. 3rd snippet is after attaching case to it. This is detail page of contact. 
2. 2nd snippet is edit tab/window of vf page.
1. 1st snippet also same as 2nd snippet. 
User-added imageUser-added imageUser-added image
VF Page:

<apex:page standardController="Contact__c" extensions="CaseController" recordSetVar="rcV" lightningStylesheets="true">
 <script type="text/javascript">
   function CloseWindow()
    { 
    window.top.close(); 
    UpdateOpener(); 
    }
    </script>

    <apex:form >
     <apex:pageBlock >
        <apex:pageBlockButtons >
          <apex:commandButton value="Save" action="{!doSave}" status="closer"/>
          <apex:actionStatus startText="(Saving...)" stopText="" onStop="CloseWindow();" id="closer"/>
          <apex:commandButton action="{!cancel}" value="cancel" />
        </apex:pageBlockButtons>
       
        <apex:pageBlockSection >
          <apex:inputField value="{!ca.Case__c }"/>
          <apex:inputField value="{!ca.Contact__c  }"/>       
        </apex:pageBlockSection>
     </apex:pageBlock>
    </apex:form>
</apex:page>
      
Apex Class:
      

public class AttachCaseController {
    public Contact__c  ca {get; set;}
     ApexPages.StandardSetController  stdControllerSet = null;
    public String caseId;
 
    public AttachCaseController(ApexPages.StandardSetController  stdController) {
       ca = new Contact__c();
        caseId = ApexPages.currentPage().getParameters().get('id');
       ca.Contact__c = caseId;
       stdControllerSet = stdController;
    }        
    public pageReference doCancel(){
     return stdControllerSet.cancel(); 
    }
    public pageReference doSave(){
        insert ca;
        System.debug('(())))'+ca);
        PageReference Pr = new PageReference('/'+caseId);
         pr.setRedirect(true);
        return pr;
    }
}

Finally, I just need some help to resolve this. Any help appreciaetd.
Thank you.