Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a VF page and on that VF page I select a project and click generate invoice, on that click an new VF page is displayed as PDF. I want to attach that generated PDF VF page to the selected project after the invoice is generated. How can I achieve it please guide me to get this problem solve.

share|improve this question
if regal answered your question, please mark it as answer and upvote it. it helps somebody to easily locate... – Baskaran S Mar 4 '14 at 10:51

Assuming "Project" is a custom object.

Enable notes and attachment for the custom object.

When you click 'generate invoice', just before redirecting to VF page use getContent() method. E.g;

public PageReference generateInvoice()
     Attachment att = new Attachment(name ='Invoice_AnyUniqueName.pdf');
     PageReference invoicePage = Page.GeneratingInvoicePage;
     invoicePage .getParameters().put('id',projectRecordId);
     // return page content as blob type
     // Alt: att.body = invoicePage .getContentAsPDF();
     att.body = invoicePage .getContent();
     // Associate with project's record Id
     att.parentid = projectRecordId;
     insert att;
     return invoicePage ;
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.