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

Is it Possible to sent Email with attachments in salesforce??



Requirement I got is like there will be a mass delete on an object based on a condition and I have to export all the values to be deleted in an excel and have to sent it in a mail to an user



can this be implemented, if so plz help me...


Thanks in advance



If you are going to handle the mass deletion through apex  then you can use apex email to send the email with the results from the deletion. There is a good deal of documentation in the technical library and some examples in cookbook regarding sending single email or email with templates. 


You can process the results, create a VF email template, then create an excel sheet (using messaging:attachment) and  then use that in the email you want to send out. 


Here is some resources to get you started:|StartTopic=Content%2Fpages_email_templates_attachments.htm|SkinName=webhelp


good luck.



make a page  to which to want send as attachment

<apex:page controller="ExcelsheetVfController" renderAs="pdf">

In this controller ExcelsheetVfController please write the logic for whatever value you want to send .

make anthoer page and controller from where you want to send mail ...In taht controller write all the logice for sending mail with attachment. Here is some you can follow .This is code tro send mail to user of contact object.Attachment is a perticular Quote detail .


public PageReference attachpdf()
Id quoteid = ApexPages.currentPage().getParameters().get('quoteid');
//cid----- means a contactId
Id cid = ApexPages.currentPage().getParameters().get('cid');
quote1 = [select id,name from Quote where id =:quoteid];
PageReference pdfPage = Page.pdfPage;
Blob pdfBlob = pdfPage.getContent();
Attachment a = new Attachment(parentId =, + '.pdf', body = pdfBlob);
insert a;
PageReference nextpage = new PageReference('/apex/convertpdf?cid='+cid+'"eid='+quoteid);
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO,'PDF Attached Successfully'));
return nextpage;
public pageReference SendEmail()
Id quoteid = ApexPages.currentPage().getParameters().get('quoteid');
Id cid = ApexPages.currentPage().getParameters().get('cid');
for (String obj : selectedNames)
contact = [select Id,name,email from Contact where name =:obj];
for(Integer i=0; i < contact.size(); i++)
quote1 = [select id,name from Quote where id =:quoteid];
Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
List<Messaging.Emailfileattachment> fileAttachments = new List<Messaging.Emailfileattachment>();
for (Attachment a : [select Name, Body, BodyLength from Attachment where ParentId = :quoteid])
Messaging.Emailfileattachment efa = new Messaging.Emailfileattachment();
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { email });
PageReference nextpage = new PageReference('/apex/convertpdf?quoteid='+quoteid+'&cid='+cid);
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO,'Email Sent Successfully'));
return nextpage;


I think It will help you..


Did this answer solve your problem ... If so please mark it solved








jay saijay sai
Hi Shank_dhel,

Salesforce is an excellent collaborative tool, but there can be some challenges when doing something unexpected  such as sending large files as email attachments.
If you can’t use cloud storage online or an internal file storage system, you may need to share content through email. So MassMailer provides best email solution for customers across the globe to send mass emails on Salesforce CRM for email marketing and prospecting emails
MassMailer DOCS makes it easier to store and mass email large file attachments through Salesforce.

For this, you might need to visit and play with this app -

For more details please click here