You need to sign in to do that
Don't have an account?
Srinivas223
Sending email with attachments from libraries
Hello All,
I am trying to send an email to owner of the record with an attachment from libraries. Here is the Sample code
I appreciate if you can help me.
Thank you!
I am trying to send an email to owner of the record with an attachment from libraries. Here is the Sample code
set<id> ContentDocId = new set<id>(); list<ContentWorkspaceDoc> contentFiles = new list<ContentWorkspaceDoc>(); contentFiles = [ SELECT id, ContentDocument.Id,ContentDocument.CreatedDate,ContentDocument.LastModifiedDate,ContentDocument.IsDeleted,ContentDocument.SystemModstamp,ContentDocument.Title,ContentWorkspace.Name FROM ContentWorkspaceDoc where ContentDocument.Title in : selectedFiles ]; if(contentFiles.size()>0) for(ContentWorkspaceDoc content: contentFiles) ContentDocId.add(content.ContentDocument.Id); system.debug('------------------ ' + contentFiles); List <ContentVersion> allDocuments = new List <ContentVersion>(); if(!ContentDocId.isEmpty()) allDocuments = [SELECT Id, Title, FileType, VersionData, isLatest, ContentDocumentId FROM ContentVersion where isLatest = true AND ContentDocumentId in:ContentDocId]; attachments = new List<Messaging.EmailFileAttachment>{}; email = new Messaging.singleEmailMessage(); emailTemplate et = [select id, name, subject, body from emailTemplate where name ='Test Template']; email.toAddresses = new String[] { 'recordOwnerEmail' }; for (ContentVersion document: allDocuments) { Messaging.EmailFileAttachment attachment = new Messaging.EmailFileAttachment(); attachment.setBody(document.VersionData); attachment.setFileName(document.Title); attachment.setFileAttachments(document); // this line causing the error } // Error: Method does not exist or incorrect signature: void setFileAttachments(ContentVersion) from the type Messaging.EmailFileAttachment
I appreciate if you can help me.
Thank you!
The method is not added in the correct object. I should be in "Messaging.singleEmailMessage()". Delete line 22 and try this: Let me know if it works.
Thanks
Regards,
Ignacio
Thank you for your time.
I tried it with email.setFileAttachments(document);
But still the same problem.
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_email_outbound_single.htm
Let me know if that solves your issue.
Thanks
Regards,
Ignacio
Thank you!
i think im doing wrong with attachments.add(document.id);