You need to sign in to do that
Don't have an account?

how to create account records from inbound mail attachment data
Hi All,
Actually i need to get an email with attachment into salesforce using email services. The data in the attachment is a list of account names,phone,billingcity. Then after i want to create records on account object automatically based on the data in the attachment. I got how to receive an attachment using email service. And now how to populate records from attachment?
Here is my code (Email Service):-
global class ProcessContactApplicantEmail implements Messaging.InboundEmailHandler {
global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email, Messaging.Inboundenvelope envelope) {
Account account;
Messaging.InboundEmailResult result = new Messaging.InboundEmailResult();
try {
if ([select count() from Account where Name =:email.subject] == 0) {
account = new Account();
account.Name = email.subject;
insert account;
} else {
account = [select Id from Account where Name =:email.subject];
}
for (Messaging.Inboundemail.TextAttachment tAttachment : email.textAttachments) {
Attachment attachment = new Attachment();
attachment.Name = tAttachment.fileName;
attachment.Body = Blob.valueOf(tAttachment.body);
attachment.ParentId = account.Id;
insert attachment;
}
for (Messaging.Inboundemail.BinaryAttachment bAttachment : email.binaryAttachments) {
Attachment attachment = new Attachment();
attachment.Name = bAttachment.fileName;
attachment.Body = bAttachment.body;
attachment.ParentId = account.Id;
insert attachment;
}
Note note = new Note();
note.Title = email.fromName + ' (' + DateTime.now() + ')';
note.Body = email.plainTextBody;
note.ParentId = account.Id;
insert note;
result.success = true;
} catch (Exception e) {
result.success = false;
}
return result;
}
}
Actually i need to get an email with attachment into salesforce using email services. The data in the attachment is a list of account names,phone,billingcity. Then after i want to create records on account object automatically based on the data in the attachment. I got how to receive an attachment using email service. And now how to populate records from attachment?
Here is my code (Email Service):-
global class ProcessContactApplicantEmail implements Messaging.InboundEmailHandler {
global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email, Messaging.Inboundenvelope envelope) {
Account account;
Messaging.InboundEmailResult result = new Messaging.InboundEmailResult();
try {
if ([select count() from Account where Name =:email.subject] == 0) {
account = new Account();
account.Name = email.subject;
insert account;
} else {
account = [select Id from Account where Name =:email.subject];
}
for (Messaging.Inboundemail.TextAttachment tAttachment : email.textAttachments) {
Attachment attachment = new Attachment();
attachment.Name = tAttachment.fileName;
attachment.Body = Blob.valueOf(tAttachment.body);
attachment.ParentId = account.Id;
insert attachment;
}
for (Messaging.Inboundemail.BinaryAttachment bAttachment : email.binaryAttachments) {
Attachment attachment = new Attachment();
attachment.Name = bAttachment.fileName;
attachment.Body = bAttachment.body;
attachment.ParentId = account.Id;
insert attachment;
}
Note note = new Note();
note.Title = email.fromName + ' (' + DateTime.now() + ')';
note.Body = email.plainTextBody;
note.ParentId = account.Id;
insert note;
result.success = true;
} catch (Exception e) {
result.success = false;
}
return result;
}
}
You are trying to achive something which is not feasible in Salesforce. You can do this kind of data import. You have to go with somekind of integration tool (informatica, mulesoft) or scheduled data loaders (Command Line Interface of DataLoader) or import wizard.
Don't follow the way you are on as that is not possible. Hope this helps!
Thanks,
Sumit