You need to sign in to do that
Don't have an account?
Staci
inbound email handler with attachments
I have an email handler creating cases from a certain email coming in and they contain attachments. If the attachment is in the body of the email the attachment works fine, but for some reason some of them come in a different way and the attachment is in an "attachment" section of the email and they get dropped off. Is there something else I need to add to get these other attachments to add to the case?
08:26:43.052 (52234000)|EXECUTION_STARTED
08:26:43.052 (52280000)|CODE_UNIT_STARTED|[EXTERNAL]|01pe0000000DcDt|CW_alertEmailHandler.handleInboundEmail
08:26:43.056 (56111000)|METHOD_ENTRY|[1]|01pe0000000DcDt|CW_alertEmailHandler.CW_alertEmailHandler()
08:26:43.056 (56125000)|METHOD_EXIT|[1]|CW_alertEmailHandler
08:26:43.056 (56293000)|SYSTEM_CONSTRUCTOR_ENTRY|[5]|<init>()
08:26:43.056 (56339000)|SYSTEM_CONSTRUCTOR_EXIT|[5]|<init>()
08:26:43.060 (60199000)|SYSTEM_METHOD_ENTRY|[12]|String.substringAfter(String)
08:26:43.060 (60247000)|SYSTEM_METHOD_EXIT|[12]|String.substringAfter(String)
08:26:43.060 (60411000)|DML_BEGIN|[16]|Op:Insert|Type:Case|Rows:1
global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email, Messaging.InboundEnvelope envelope) {
Case c;
Messaging.InboundEmailResult result = new Messaging.InboundEmailresult();
try
{
c = new Case();
c.recordTypeId = '012f00000000JLc';
c.OwnerId = '00G30000001oUSL';
c.Site_Code__c = email.subject.substringAfter('##');
c.AccountId = '0013000000aRZ67';
c.Description = email.plainTextbody;
c.Subject = email.subject;
insert c;
//to save attachment to case
for(Messaging.Inboundemail.TextAttachment tAttachment:
email.textAttachments) {
Attachment attachment = new Attachment();
attachment.Name = tAttachment.fileName;
attachment.Body = Blob.valueOf(tAttachment.body);
attachment.ParentId = c.Id;
insert attachment;
}
result.success = true;
}catch (Exception e){
result.success = false;
result.message = 'Oops, I failed.' + e.getMessage();
}
return result;
}}
Also you should add your attachments to a list and insert them outside of your loop - this will save on DML limits and system resources.