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">
<script>
function newpagePDF() {
alert('Hi11');
var stringcase = '{!caseid }';
var newpage = window.Open('/apex/ZEB_RMA_Pdf?CaseId='+stringcase );
}
<apex:form >
<div style="height:43px; background-color:white">
<br/>
<h3 style="font-size: large;">
CONFIRMATION
</h3>
</div>
<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}" />
</apex:pageBlock>
</apex:form>
</apex:page>
controller : public class ZEB_RMA_ConfirmCont {
/******Variables*****/
public String caseid{get;set;}
public Case objCase{get;set;}
Public list<attachment> listattachmnt{get;set;}
Public Integer intattchmntsize{get;set;}
/******Constructor***/
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];
}
}
/******Methods*****/
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;
pgref.setRedirect(True);
return pgref;
}
}