You need to sign in to do that
Don't have an account?
Email attachments to Salesforce, make them automatically go into SF Content
Hello,
I'm really excited about SF Content being free for all my users, and I think I have a great way to start using it. We have these PDF reports that go out to our customers, and I'd love it if we could bcc these emails to a Salesforce email address which would grab the attachments and stash them in a workplace (the same workplace for all attachments). I think this should be pretty easy, but I'm not sure where to begin.
I know that I'd create an email service, and I'd obviously add that email address to the emails being sent out, and create a new Apex class, but I looked through the Winter '10 API guide and didn't see what kind of calls I'd make - if anyone could give me an idea of what the code would look like, I'd really appreciate it!
Help?
I'm pretty sure you can use ContentVersion to post new documents. In the Email Service class you should be able to grab the attachment and then insert a new ContentVersion.
http://www.salesforce.com/us/developer/docs/api/index.htm
Here's the code that we ended up writing. For simplicity, it only allows 1 attachment per email, and we needed to put them in a specific workspace named "C6 Reports", so that's what we did - it would be easy to modify for your own workspace. Unit tests included! :-)
Hi,
When I try to save the code, it complains sObject type 'ContentWorkspace' is not supported. I'm using the free enterprise edition.
Thanks in advance!
You probably don't have Content enabled. Setup-->Customize App-->Salesforce CRM Content-->Settings
Thanks very much for the quick reply! It does not seem to be enabled in the developer edition though.
// parentId is the Id of the record you want to attach it to
Id parentId; // Assign a value to this
list<Attachment> docs = new list<Attachment>();
if(email.binaryAttachments != null)
{
for(Messaging.InboundEmail.BinaryAttachment attachment : email.binaryAttachments)
{
Attachment doc = new Attachment();
doc.Name = attachment.fileName;
doc.ContentType = attachment.mimeTypeSubType;
doc.Body = attachment.body;
doc.ParentId = parentId;
docs.add(doc);
}
if(docs != null)
{
insert docs;
}
}