+ Start a Discussion
DJ 367DJ 367 

is there any way to show attachment in the email?

Hello All,

I am sending email thru trigger with attachment however after sending email , attachment is being received however when I checked into the salesforce attachment is not visible into the email.

Thanks
Best Answer chosen by DJ 367
Bhargavi TunuguntlaBhargavi Tunuguntla
Hi

The attachment will not automatically get saved into the salesforce attachment.You can insert into the attachment object in your trigger:
 
private final Applicant__c applicant;
public Blob resume {get; set;}
public String contentType {get; set;}
public String fileName {get; set;}

 Attachment attach=new Attachment();
      attach.Body=resume;
      attach.Name=filename;
      attach.ContentType=contentType;
      attach.ParentID=applicant.id;

Thanks.

All Answers

Bhargavi TunuguntlaBhargavi Tunuguntla
Hi

The attachment will not automatically get saved into the salesforce attachment.You can insert into the attachment object in your trigger:
 
private final Applicant__c applicant;
public Blob resume {get; set;}
public String contentType {get; set;}
public String fileName {get; set;}

 Attachment attach=new Attachment();
      attach.Body=resume;
      attach.Name=filename;
      attach.ContentType=contentType;
      attach.ParentID=applicant.id;

Thanks.
This was selected as the best answer
Ajay K DubediAjay K Dubedi
Hi DJ,

Below Sample code can fulfill your requirements. Hope this will work for you.

//Put your record id in ParentId
List<Attachment> attList = [SELECT id, Name, body, ContentType FROM Attachment WHERE ParentId = : opp.id];
// List of attachments handler
Messaging.EmailFileAttachment[] efaList = new Messaging.EmailFileAttachment();
for(Attachment att : attList)
{ // Create the email attachment Messaging.EmailFileAttachment efa = new Messaging.EmailFileAttachment();
efa.setFileName(att.Name);
efa.setBody(att.body);
efa.setContentType(att.ContentType);
efa.setInline(false);
efaList.add(efa); }
// Attach files to email instance
email.setFileAttachments(efaList);

Please mark this as best answer if this solves your problem.

Thank you
Ajay Dubedi