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
khillan bhardwajkhillan bhardwaj 

Attachment is not created while creating record by using inbound email service

hi all,

 i am using inbound email service in which i am creating new record  on the base of the email recieve configure in email service setting . but i am recieving the email the record is created by attachment record is not created my code is as follow . if some one know solution plz let me know

 

global class EmailServiceHandler implements Messaging.InboundEmailHandler {
global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email, Messaging.InboundEnvelope envelope) {
Messaging.InboundEmailResult result = new Messaging.InboundEmailresult();
EmailServiceDemo__c esd=new EmailServiceDemo__c(name=email.subject);
esd.EmailPlainText__c=email.plainTextBody;
System.debug('========================email.plainTextBody'+email.plainTextBody);
esd.email__c='test@gmail.com';
upsert esd;


// Save attachments, if any
if (email.textAttachments != null)
{
System.debug('===================Text attachment i not null');
for(Messaging.Inboundemail.TextAttachment tAttachment : email.textAttachments)
{
Attachment attachment = new Attachment();
attachment.Name = tAttachment.fileName;
attachment.Body = Blob.valueOf(tAttachment.body);
attachment.ParentId = esd.Id;
insert attachment;
}

}

//Save any Binary Attachment

if (email.binaryAttachments != null)

{
System.debug('===================binary attachment i not null');
for(Messaging.Inboundemail.BinaryAttachment bAttachment : email.binaryAttachments) {
Attachment attachment = new Attachment();

attachment.Name = bAttachment.fileName;
attachment.Body = bAttachment.body;
attachment.ParentId = esd.Id;
insert attachment;
}
}

//Attachment a=new Attachment();
// a.body=email.TextAttachment[0].body;
// a.parentId=esd.id;
return result;
}
}

 

thanks 

khillan singh

Best Answer chosen by Admin (Salesforce Developers) 
khillan bhardwajkhillan bhardwaj

yes problem is essy there is no problem in code you should email service configuration in which you set accept email attachment none . you should set it all testattachment or binary attachment