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

Sending an email and building a object.
Hi, I have a question about sending a email and then building an object. I created a method that parses an email out and sends that data in an email my salesforce account. I was wonder how on the salesforce end do you parse that data and add it to an object that is already been created.
Thanks for any help you can give.
Hi
You need to perform a SOQL query against the target object's table to generate a result set of records to which you want to attach (or update) the new data. It easiest if you can use an attribute of the email's envelope such as the sender's email like this "SELECT id FROM myobject__c.email WHERE myobject__c.email = email.FromAddress". Once you have the record id, you can use the data in the email to either update information in the original record or add a related record such as a Task with the email's data.
Here's a sample where I do both:
global class LeadRepliesService implements Messaging.InboundEmailHandler { global Messaging.InboundEmailResult handleInboundEmail(Messaging.inboundEmail email, Messaging.InboundEnvelope env){ // Create an inboundEmailResult object for returning the result of the Apex Email Service Messaging.InboundEmailResult result = new Messaging.InboundEmailResult(); String myPlainText= ''; // Add the email plain text into the local variable myPlainText = email.plainTextBody; // New Task object to be created Task[] newTask = new Task[0]; // Try to lookup any Leads based on the email from address // If there is more than 1 lead with the same email address, // the first one matched will be assigned the email. // AN order by CAN TARGET THE ACTIVE LEAD IF THERE IS A CONSISTENT RULE FOR PREDICTION Lead vLead = [Select Id, OwnerId From Lead l Where Email = :email.fromAddress AND IsConverted = false Limit 1]; //Check for email opt out phrase in Subject and if found, set Lead to Dead and Email Opt Out if (email.Subject == 'I No Longer Want to Receive Information About your company'){ vLead.Lead_Temperature__c = 'Dead'; vLead.HasOptedOutOfEmail = true; update vLead; } else { // Add a new Task to the lead record we just found above. newTask.add(new Task( OwnerId = vLead.OwnerId, Subject = 'New Email: ' + email.subject, Description = myPlainText, Priority = 'High', Status = 'Inbound Email', IsReminderSet = true, ReminderDateTime = System.now(), WhoId = vLead.Id)); // Insert the new Task insert newTask;
(caveat: I clipped this from a larger script, might be missing a bracket or variable declaration or something)
Hope that helps,
Luke C
Hi, I can up with something like this but I still get an error:
}
This is the error i keep on getting:
Class.Person.handleInboundEmail: line 13, column 24
External entry point
21
04/04/1986
Dallas
saint anthony
11214
Thank you for any help you can give.