I have a generate pdf button which open the pdf and simultaneously store the same pdf as an attachment in Case object. But now i want is,pdf should open in new tab leave generate pdf button pafe as it is.

Can someone help me.

My vf page:

<apex:page controller="ZEB_RMA_ConfirmCont">


  function newpagePDF() {
      var stringcase = '{!caseid }';
      var newpage = window.Open('/apex/ZEB_RMA_Pdf?CaseId='+stringcase );

    <apex:form >
          <div style="height:43px; background-color:white">
             <h3 style="font-size: large;">

          <apex:pageBlock >
              <apex:pageMessage summary="Following Web Orders with RMA-{!$CurrentPage.parameters.CaseNo} were Successfully Submitted." severity="Info" strength="2"/>
              <apex:commandButton value="Generate Pdf" action="{!generatePdf}" />




controller : public class ZEB_RMA_ConfirmCont {

 public String caseid{get;set;}
 public Case objCase{get;set;}
 Public list<attachment> listattachmnt{get;set;}
 Public Integer intattchmntsize{get;set;}


   public ZEB_RMA_ConfirmCont (){

         caseid = ApexPages.currentPage().getParameters().get('CaseId');        
         objCase = new Case();
         listattachmnt = [select id from attachment where parentid = :caseid ];
         intattchmntsize = listattachmnt.size();
         intattchmntsize  = intattchmntsize + 1;

         if(caseid != null){
            objCase = [Select Id,Account.Name,Account.BillingAddress,Account.BillingStreet,Account.BillingCity,Account.BillingCountry,Account.BillingPostalCode,Account.Phone,Account.Fax,Contact.Name,Contact.Phone,Contact.Email,Contact.Fax,
                       (Select Id,Case__r.CaseNumber,Product__c,Product_Name__c,Serial_Number__c,Service_Entitlement__c From RMA_Returns__r)
                       From Case 
                       Where Id =: caseid];


     Public Pagereference generatePdf(){
     Pagereference pgref = new Pagereference('/apex/ZEB_RMA_Pdf?CaseId='+caseid );
     Blob pdfPageBlob;
     pdfPageBlob = pgref .getContentAsPDF();
     Attachment objattchd = new Attachment();

     objattchd.name = 'pdf.pdf'+'_'+caseid+ '_Attachment_no_'+intattchmntsize; 
     objattchd.ContentType = 'application/pdf';
     objattchd .Body = pdfPageBlob;
     objattchd.ParentId = caseid ;
     Insert objattchd;
     return pgref;

  • I have modified my script..now trhe script runs.it also print the alert statement and value of caseid..But i am now getting a error now "window.open is not a function"can someone help.My modified script <script> function newpagePDF() { alert('Hi11'); var stringcase = '{!caseid }'; var newpage = window.Open('/apex/ZEB_RMA_Pdf?CaseId='+stringcase ); } </script> Jun 23, 2015 at 6:17

3 Answers 3


Create one javascript like,

<script type="text/javascript">
    function newpagePDF() {
        var newpage = window.Open('/apex/ZEB_RMA_Pdf?CaseId='+{!caseid}');

Change your command line code to,

 <apex:commandButton value="Generate Pdf" action="{!generatePdf}" onclick="newpagePDF()"/>

I think you have mentioned "window.open" as "windows.open" in onclick event of commandbutton.

You can see page loading (jquery or java script) errors through,right click and click "Inspect Element".Click Console and verify the list of errors there for debugging.

  • I tried you Way sir.but stil the pdf is opening in same page. Jun 22, 2015 at 12:45
  • <apex:commandButton value="Generate Pdf" action="{!generatePdf}" onclick="newpagepdf()" /> change command button code like this and create one script like above. Jun 22, 2015 at 12:47
  • Code which you have posted don't have onclick script .@Ankita Singh Jun 22, 2015 at 12:49
  • I wrote the same thing ..still it doesnot work <apex:commandButton value="Generate Pdf" action="{!generatePdf}" onclick="newpagepdf()" /> Jun 22, 2015 at 12:49
  • Have the include this script too,<script> function newpagePDF() { var newpage = window.Open('/apex/ZEB_RMA_Pdf?CaseId='+{!caseid}'); } </script> Jun 22, 2015 at 12:53

1) Create a visualforce page that takes the caseid for the controller.

2) Create an link on your page

3) place target="_blank" on your 'a' tag

the code should look like this:

    <a href='/apex/ZEB_RMA_Pdf?Id='{!caseid}' target='_blank' />
  • i have done that but i need to open it on click of a command button Jun 23, 2015 at 6:15

You can use renderAs='PDF' in your visualforce page as below

This will always open new window and display PDF page layout.

  • I cannot do that ..i have tostore that pdf as an attachment too in Case Object Jun 22, 2015 at 12:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .