I have a visualforce renderas=Pdf, I created a button to save them in notes and attachments related list, this work fine, but I can't get the value record information in my attachment.
If you can help, I appreciate.
public class VFController {
// Constructor - this only really matters if the autoRun function doesn't work right
public Opportunity o {get; set;}
public VFController(ApexPages.StandardController stdController) {
this.o = (Opportunity)stdController.getRecord();
}
// Code we will invoke on page load.
public PageReference autoRun() {
String theId = ApexPages.currentPage().getParameters().get('id');
if (theId == null) {
// Display the Visualforce page's content if no Id is passed over
return null;
}
list<opportunity> oportunidade = [SELECT id, name, Numero_Sequencial__c FROM Opportunity WHERE id =:theId];
for (Opportunity o: oportunidade) {
// Do all the dirty work we need the code to do
PageReference pdf = Page.Footer_Helitene;
Attachment attach = new Attachment();
Blob body;
try {
// returns the output of the page as a PDF
body = pdf.getContentAsPDF();
// need to pass unit test -- current bug
} catch (VisualforceException e) {
body = Blob.valueOf('Some Text');
}
attach.name = o.name+' '+o.Numero_Sequencial__c+'.pdf' ;
attach.Body = body;
attach.ParentId = o.id;
attach.IsPrivate = false;
attach.ContentType = 'application/pdf';
insert attach;
}
// Redirect the user back to the original page
PageReference pageRef = new PageReference('/' + theId);
pageRef.setRedirect(true);
return pageRef;
}
}