function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
amr.rsamr.rs 

How to attach the rendered PDF to the Opportunity?

Hi,

 

We created a VisualForce Page that generates a quote pdf. But while emailing to contact, we need to save it in the local system and then to attach with the Opportunity.

 

But is there anyway to automatically attach the quote pdf in the Opportunity.

 

Thanks.

 

Regards,

AMR.

bob_buzzardbob_buzzard

You can create a PageReference pointing to the visualforce page, and then execute the getContentAsPDF() method to retrieve the content as a Blob, and then use this as the body for the attachment.  However, there are some restrictions on when you can call this method (not in a trigger, for example).  I've used this in a visualforce controller so that when the user clicks a button it retrieves the PDF. attaches it to the opportunity and then generates an apex email.

amr.rsamr.rs

Bob, Thanks for the reply. I'm just a beginner in SF Development.

 

Can you let me know whether it's possible in Professional Edition?

 

Thanks.

 

Regards,

AMR.

bob_buzzardbob_buzzard

You won't be able to do this in PE by default, as you don't have apex code.  You may be able to produce a package from a  developer edition that has this functionality.  I've not spent much time in PE so I dont know how achievable this is, but I know someone who has.  I'll ping abhi_the1 and see if he can offer any assistance.

amr.rsamr.rs

Thanks Bob! :)

goabhigogoabhigo

Thanks Champ, I am here :)

 

Yes this was one of the common problems I came across in PE. I believe you have a button to show this PDF. This can be used as 'preview' of Quote PDF. If you need the same to be attached, you can use VF templates. You can automate this by using workflow or you can send the email within Salesforce by selecting this template.

 

You have a tag - <messaging:attachment renderAs="pdf" filename="TheFileNameAsUrWish.pdf">, which attaches the PDF to the email. Under this tag, just copy the codes that are put under <apex:page> of your VF page. Replace {!objectName.FieldName__c} with {!relatedTo.FieldName__c} [not sure about this though, please search for Visualforce email templates)].

 

There are some known issues with this:

 

One of them which I myself found -

http://boards.developerforce.com/t5/Visualforce-Development/Attachment-used-in-email-template-is-not-saved/m-p/282245/highlight/true#M35939 

 

Let me know if this helps. 

amr.rsamr.rs

Thanks Abhi.

 

Actually i was planning to make it as an email template. But the issue is the pdf is not attached under the opportunity.


Like everytime we need to generate the pdf.

 

The thing i'm planning is to create a new button for Send Email which adds this email template as the default one so the task will be reduced somewhat.

 

But correct me if i'm wrong. Also let me know anything efficient than this.

 

Thanks.

 

Regards,

AMR. 

goabhigogoabhigo

Hope you have workflows enabled. Yes, attachment is the problem. That needs apex coding.

 

The idea of having a button - Send Email, to is cool, but I am not sure how you will send the email. Button can open a VF page, or execute javascript (in that you can make a checkbox true and that will fire the workflow). As far as I know there is no better way than this (though the issue of PDF not attached is still a head ache).

amr.rsamr.rs

Abhi,

 

To be frank i never created a workflow. Have to read about it :(

 

Will comeback after reading it.

 

Thanks.

goabhigogoabhigo

Thats easy.

 

But it would be good to check whether your Org has workflow enabled (or to be specific it would be good whether your Org has purchased workflows).

 

To check : Click on Setup - Create (under App Setup). If you don't see 'Workflow & Approvals' link, then you don't have them !!

amr.rsamr.rs

No :( 

goabhigogoabhigo

So...

 

The email template is the easier way, but if you want attachment to be attached to Opp, then back to your old way :(

I will let you know if anything else strikes. 

amr.rsamr.rs

Abhi,

 

Thanks a lot for spending your time for me.

 

I'll try to come up with some sort of solution.

 

Thanks.