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
teknicsandteknicsand 

fileattachments

I have a visualforce pdf as an attachment already. I need to add another static file to be added as an attachment. Should it be in the documents section or the static resource section?

 

 

PageReference opppdf = Page.opppdf; opppdf.getParameters().put('id',opp1.id); Blob pdf = opppdf.getContent();

 

 

Messaging.EmailFileAttachment mailAttachment; mailAttachment = new Messaging.EmailFileAttachment(); mailAttachment.setFileName('test1.pdf'); mailAttachment.setBody(pdf);

 

for the second attachment which is static file

 

 

Messaging.EmailFileAttachment mailAttachment1; mailAttachment1 = new Messaging.EmailFileAttachment(); mailAttachment1.setFileName('test2.pdf'); mailAttachment.setBody(pdf1); mail.setFileAttachments(new Messaging.EmailFileAttachment[] { mailAttachment, mailAttachment1 })

 how do i access the content of the file and attach it to the email?

 

 

 

- Sand

 

 

 

Venkat PolisettVenkat Polisett

If you put it as a static resource, you can access it as $Resource.<yourresourcename>.

 

But, if you are uploading these docs to your org to send as an email attachment, why don't you use the "Content Delivery" feature that is introduced in Spring '09. You simply send a link to the content (after you upload it to your org) as an email and you have complete control as to whether the recipient can view/download etc that content etc.,. No more huge file attachments.

 

Take a look at this feature. Ofcourse, this feature needs to be enabled by your Salesforce support rep, though.

Message Edited by Venkat Polisett on 03-19-2009 08:08 AM
teknicsandteknicsand

How can I access the static resource within a controller or apex code? I can use it as merge field within Visualforce markup, but not sure how to access from within apex.

 

Content delivery is something worth considering, but right now, I just need to get this one part to finish what I've been working on.

 

Thanks

 

Sand

Message Edited by teknicsand on 03-19-2009 08:03 AM
Venkat PolisettVenkat Polisett

teknicsand wrote:

How can I access the static resource within a controller or apex code? I can use it as merge field within Visualforce markup, but not sure how to access from within apex.

 

Content delivery is something worth considering, but right now, I just need to get this one part to finish what I've been working on.

 

Thanks

 

Sand

Message Edited by teknicsand on 03-19-2009 08:03 AM

 

 

As of Sprint '09, there is no direct way to get the URL or Resource content from APEX. But here is a work around that is described at the following blog entry. Scroll towards the bottom to see a couple of APEX functions.

 

Getting Resource URLs from APEX

 

 

Good luck.

Message Edited by Venkat Polisett on 03-19-2009 11:16 AM
teknicsandteknicsand

That seems odd to me that there is no way to attach a file as an attachment using the sendemail api.

Just to give more context to my issue. I'm making a callout from a visualforce controller to an apex class which uses the sendemail api to send out emails. I'm passing relevant information to it along with blob of the first attachment (which is a visualforce page being rendered as a pdf). If I could do the same for the second attachment (which is a static pdf file)in any way,either in the controller code or in the apex email class.

 

I tried that work around. Didnt exactly work for me. May have to give it another shot

teknicsandteknicsand
I get this error

Compile Error: unexpected char: 0xȹ8 at line 60 column 100

 

when I try out the workaround mentioned in that link which return the url for a static resource