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

create tasks from inbound email
Hello Gurus,
I hope you are well.
I got a request to attach inbound emails to certain SF records if the email has been sent from SF. Similiar to the email2salesforce functionality but for custom objects.
What I am trying to achieve is that I want to look for the record ID in the textbody of the email. The user sends out an email using a template containing the record ID and if someone respondes (which will be sent to a routing address) the class should look for the record ID and attach it appropriately. I hope that made sense ?!
What I found is the following and it does work fine for contacts:
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_email_inbound_using.htm
I modified the following part to:
-------------------------------------
try {
Contact vCustom = [SELECT Id, Name, Email
FROM CustomObject__c
WHERE Id = :email.TextBody
LIMIT 1];
// Add a new Task to the contact record we just found above.
newTask.add(new Task(Description = myPlainText,
Priority = 'Normal',
Status = 'Inbound Email',
Subject = email.subject,
IsReminderSet = true,
ReminderDateTime = System.now()+1,
WhatId = vCustom.Id));
insert newTask;
-----------------------------------
However, the error I am getting is "Variable does not exist: TextBody". According to the WSDL the field does exist though.
Can you please let me know what I do wrong? If you have an easier solution on how to attach incoming emails (to custom objects) , then please let me know!
Any questions please let me know!
Thanks in advance and have a great day,
Christian
Actually got it working but had to use the subject line of the email and include a unqiue ID which is an auto-number field using a particular format such as "AI=0000"
try {
String customID;
Pattern p = Pattern.compile('^(.*)(ai\\=\\d+)(.*)$');
Matcher pm = p.matcher( email.subject);
if( pm.matches() ){
customID = pm.group(2);
}
System.debug('customID _' + customID + '_');
Opportunity vCustom = [SELECT Id, Name, Custom_Unique_Field__c
FROM CustomObject__c
WHERE Custom_Unique_Field__c =: customID
LIMIT 1];
// Add a new Task to the contact record we just found above.
newTask.add(new Task(Description = myPlainText,
Priority = 'Normal',
Status = 'Inbound Email',
subject = email.subject,
IsReminderSet = true,
ReminderDateTime = System.now()+1,
whatId = vCustom.Id
));
All Answers
Actually got it working but had to use the subject line of the email and include a unqiue ID which is an auto-number field using a particular format such as "AI=0000"
try {
String customID;
Pattern p = Pattern.compile('^(.*)(ai\\=\\d+)(.*)$');
Matcher pm = p.matcher( email.subject);
if( pm.matches() ){
customID = pm.group(2);
}
System.debug('customID _' + customID + '_');
Opportunity vCustom = [SELECT Id, Name, Custom_Unique_Field__c
FROM CustomObject__c
WHERE Custom_Unique_Field__c =: customID
LIMIT 1];
// Add a new Task to the contact record we just found above.
newTask.add(new Task(Description = myPlainText,
Priority = 'Normal',
Status = 'Inbound Email',
subject = email.subject,
IsReminderSet = true,
ReminderDateTime = System.now()+1,
whatId = vCustom.Id
));
Exactly what I needed!
But can't get mine to work...
Getting Error: Compile Error: Illegal assignment from LIST<Test_Email__c> to SOBJECT:Opportunity at line 30 column 7
Any help would be GREATLY appreciated :)
well your list must query a standard or custom object.