This Is Extension Controller public with sharing class costsheet {
public String OrderId; public costsheet(ApexPages.StandardController controller) { //OrderId= (ID)Order.getRecord().id; Id Order=Apexpages.currentpage().getParameters().get('id');
} public pageReference SaveAttachment() { blob pdfBody; PageReference thePDF = new PageReference('/apex/costsheet?id='+order.id);
if (attach == null){ ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Error will Saving a file .Please check the content of the file')); } if (attach != null){ ApexPages.addmessage(new ApexPages.message(ApexPages.severity.CONFIRM,'Quote Pdf generated successfully'));
All Answers
public with sharing class costsheet {
public String OrderId;
public costsheet(ApexPages.StandardController controller) {
//OrderId= (ID)Order.getRecord().id;
Id Order=Apexpages.currentpage().getParameters().get('id');
}
public pageReference SaveAttachment() {
blob pdfBody;
PageReference thePDF = new PageReference('/apex/costsheet?id='+order.id);
thePDF.setRedirect(true);
if(Test.isRunningTest()) {
pdfBody = blob.valueOf('Unit.Test');
} else {
pdfBody = thePDF.getContentAsPDF();
}
Attachment attach = new Attachment();
attach.body = pdfBody;
attach.Name='CostSheet '+System.Today();
attach.ParentID=OrderId;
Insert attach;
if (attach == null){
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Error will Saving a file .Please check the content of the file'));
}
if (attach != null){
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.CONFIRM,'Quote Pdf generated successfully'));
}
PageReference qtpage = new PageReference('/' + Quote.Id);
qtpage.setRedirect(true);
return qtpage;
}
}