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
lalilali 

how to close the window after performing the action method on a page

Hi,
 I have a blank page with an action method that performs some database inserts and finally after that I need to close this window.
 
following is my code.my page has only the following code:

<apex:page action="{!generatePDF}"  controller="VFC_ER_GeneratePDF"  showheader="false"  standardStylesheets="false" >
</apex:page>

In the controller 'VFC_ER_GeneratePDF' I have a method called generatePDF with the following code.  and finally after that I want to close this window. How do I do that pls help...

public class VFC_ER_GeneratePDF {
    public string  sigID;
    public string ERID;
    
    public VFC_ER_GeneratePDF() {
        
        sigID = System.currentPageReference().getParameters().get('sigID'); 
        ERID = System.currentPageReference().getParameters().get('id'); 

    }
    
      public pageReference  generatePDF() {
      
      PageReference pdf = New PageReference ('/apex/'+ 'vf_SignatureCaptured');
        // add parent id to the parameters for standardcontroller
        pdf.getParameters().put('id',ERID);
        pdf.getParameters().put('sigID',sigID);
      
        // create the new attachment
        Attachment attach = new Attachment();
     
        // the contents of the attachment from the pdf
        Blob body;
     
        try {
                // returns the output of the page as a PDF
                body = pdf.getContentAsPDF();
            }
          catch (VisualforceException e) 
            {
                // need to pass unit test -- current bug  
                body = Blob.valueOf('Some Text');
            }
     
        attach.Body = body;
        attach.Name = ERId + '.pdf';
        attach.IsPrivate = false;
        attach.ParentId = ERId;
        insert attach;
        system.debug('Final Attachement' + attach);
          
        //delete the signature attachment 
          List<Attachment> attachedFiles = [select Id from Attachment where id =:sigID limit 1];
        if( attachedFiles != null && attachedFiles.size() > 0 ) 
        {
           delete attachedFiles;
        }  
        
        //this is where I need to close this window.
      
      }      
  
}
 
Deepak Kumar ShyoranDeepak Kumar Shyoran
You can use window.close() on your page to close the window also can set the delay time. Put this code on your VF page inside
<script>window.close(); </script>
and it will close your window after loading your VF page and calling your method which is in your action attribute of your ApexPage.