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
Apex codingApex coding 

How to upload a file and send that file and an attachment through mail

Hi
 
I want to upload a file  from my local drive and send that file as an attachment using Apex
for this to upload the file Iam using a standard object of Salesforce Document here
After uploading the file through URL the size of the file is 0 bytes
How to send this document as an attachment through email
can any one please send me the code to solve my issue
 
 
This is the code what Iam writing
 
Document doc=new Document();
Folder fold=new Folder();
fold.AccessType='Public';
fold.IsReadOnly=false;
fold.Name='MyFolder';
fold.DeveloperName='MyFolder';
fold.Type='Document';

Folder[] fld = [select f.id from Folder f  where f.Name = : ('MyFolder')];


doc.Name='MyTestDoc';
doc.URL = 'c:/ImpUrls.txt';
//doc.IsPublic = true;
doc.FolderId = fld[0].id;
//doc.ContentType = 'txt';
//doc.BodyLength=900;
insert doc;
 
regards
sunil
 
 
marie.tournemarie.tourne
Hello,

I am trying to do the same as you.

My idea is, once the file is uploaded, it can be be included as an attachment using emailauthor.jsp, this is done according the method described here: to add an attachment, parameter to be added to the url is id="<attachment id>".
This part actually works without file uploading. I guess you could also use pure Apex function to email the file (described in Apex Language Reference). In my case I prefer the S Controls as users are able to modify the email, add attachments, etc.

Anyway, my problem is that using the code described in your post, the file is not actually uploaded in Salesforce.com, my local path is only saved in a 0 bytes document. So it can't be added in an email.

I could not find any documentation on Document class (?), so if you did I would be very interested and to find a way to upload the file.

Thanks
Rgds