You need to sign in to do that
Don't have an account?
adampro
Can't get attachment from Email Service
Hi,
I'm creating an email service, but I can't seem to get it to include the attachments. I've found plenty of example code on this yet somehow it's not working. It will create a task like I want it to, but it never associates the attachments.
Task[] newTask = new Task[0]; newTask.add( new Task ( Subject = subject, OwnerId = matchUpp.OwnerId, Type = 'Email', ActivityDate = system.now().date(), Status = 'Completed', Description = BodyText, Priority = 'Normal', WhatId = matchOpp.Id ) ); insert newTask; if ( email.binaryAttachments != null && email.binaryAttachments.size() > 0 ) { for (Messaging.Inboundemail.Binaryattachment bAttachment : email.binaryAttachments ) { /* Attachment attachment = new Attachment(); attachment.Name = bAttachment.fileName; attachment.Body = bAttachment.body; attachment.ParentId = newTask[0].Id; insert attachment; */ Attachment a = new Attachment(ParentId = newTask[0].Id, Name = bAttachment.filename, Body = bAttachment.body); insert a; } } if (email.textAttachments != null && email.textAttachments.size() > 0) { for (Messaging.Inboundemail.Textattachment tAttachment : email.textAttachments ) { /* Attachment attachment = new Attachment(); attachment.Name = tAttachment.fileName; attachment.Body = blob.valueOf(tAttachment.Body); attachment.ParentId = newTask[0].Id; insert attachment; */ Attachment a = new Attachment(ParentId = newTask[0].Id, Name = tAttachment.filename, Body = blob.valueOf(tAttachment.body)); insert a; } }
For whatever reason, this won't seem to work. I've tried attaching .txt, .jpg, and .png files and none have shown up. Does anyone see something I'm doing wrong?
Thanks
Setup > Develop > Email Services
When you actually create your new Email Service, there is a drop-down setting for selecting the Attachment Type. This has caught me out in the past - I would select Both in this and re-try.
Text attachments only Binary attachments only All
All Answers
Setup > Develop > Email Services
When you actually create your new Email Service, there is a drop-down setting for selecting the Attachment Type. This has caught me out in the past - I would select Both in this and re-try.
Text attachments only Binary attachments only All
That's exactly what it was. Thank you so much!