You need to sign in to do that
Don't have an account?
dselat
Visual force email template and attachment file.
Hello, I am looking to have attachments (i.e. actual physical file and not the link) in vf email template. How do i accomplish this? Appreciate if you have any sample code. Thanks
I am not clear with the requirement. Do you want attachment contents should be shown in email itself?
Hi ,
I am having the same requirement in my project. we need to attach the file present in Notes&Attachment related list in the visualforce email template as an (real)attachment(not as a link to the attachment).So that, users can directly download/view the file from email attachment , they don;t need to login to salesforce to view/download it. Thanks in advance.
Any help on this is much appreciated.
I am also looking for a solution to create a VF E-Mail template which would have the Link to the Attachment which is associated with the Opportunity Record.
Can some one help in please
Hi All,
I have got this to work myself and used in my project. Here is the sample code.
************* VF Component *******************(Component Name say : testemail)
<apex:component controller="emailattachment" access="global">
<apex:attribute name="emailatt" description="Attachment URL" access="global" type="String" assignTo="{!Oppid}"/>
<apex:repeat value="{!attach}" var="att">
<a href="{!att}">{!attach[att]} </a> <br/>
</apex:repeat>
</apex:component>
*********************************************************
******************** Component Controller Class *********************************
public class emailattachment {
public string Oppid;
public string attid;
public Map<String,String> urlMap=new Map<String,String>();
public List<Attachment> attach;
public string getOppid() {
return null;
}
public void setOppid(String s) {
Oppid=s;
}
public Map<String,String> getattach() {
attach=[Select id,name From Attachment Where Parentid=:Oppid];
for(Attachment att1:attach) {
String urls=URL.getSalesforceBaseURL().toExternalForm()+'/servlet/servlet.FileDownload?file='+att1.id ;
urlMap.put(urls,att1.Name);
}
return urlMap;
}
public void setattach(List<Attachment> ata) {
attach=ata;
}
}
***********************************************************************************
****************VF Email Template*********************************
<messaging:emailTemplate subject="Email Subject" recipientType="User" relatedToType="Opportunity">
<messaging:htmlEmailBody >
// Body of your email
// Below is the link to the attachments associated with the opportunity record
<c:testemail emailatt="{!relatedTo.id}" rendered="true">
</c:testemail>
</messaging:htmlEmailBody>
</messaging:emailTemplate>
*************************************************************************
First create the VF component and custom controller for it. and then include the component in the vf email to get the link to the associated attachments. Note that, with this approach users will be required to login to salesforce to access the files.
Please mark it as a Solution if it answers your question.
Thanks,
Koushik
Any suggest for the way not required to login to salesforce ?
Is it possibile show a link of attachment to anyone in the world without access of salesforce ?
<apex:repeat var="cx" value="{!relatedTo.Attachments}">
<tr>
<td style="padding: 5px;">Attachment:</td>
<td style="padding: 5px;"><a href="https://c.cs14.content.force.com/servlet/servlet.FileDownload?file={!cx.id}">{!cx.Name}</a></td>
</tr>
</apex:repeat>