You need to sign in to do that
Don't have an account?
Sharon Prager
Help with Inbound email testing
I am not a developer, but managed to put together an email handler class. Most immediate question, how do I write a test for this so I can put in production? Next question, how do I parse so that I can grab everything between ";". For example, Status: Closed; Priority: Low. Thanks!
global class CaseUpdateEmailHandler implements Messaging.InboundEmailHandler {
global Messaging.InboundEmailResult handleInboundEmail(
Messaging.InboundEmail email,
Messaging.InboundEnvelope envelope)
{
String subject = email.subject;
Pattern idPattern = Pattern.compile('500[A-Za-z0-9]{15}');
Matcher matcher = idPattern.matcher(subject);
if (!matcher.find()) System.assert(false, 'No Case Id in subject!');
Case caset = [SELECT Status, Priority FROM Case WHERE Id = :matcher.group(0)];
String[] emailBody = email.plainTextBody.split('\n', 0);
String Status1 = emailBody[0].substring(7);
String Priority1 = emailBody[1].substring(9);
caset.Status = Status1;
caset.Priority = Priority1;
update caset;
Messaging.InboundEmailresult result = new Messaging.InboundEmailResult();
result.message = 'Case Status is now' + caset.Status;
return result;
}
}
global class CaseUpdateEmailHandler implements Messaging.InboundEmailHandler {
global Messaging.InboundEmailResult handleInboundEmail(
Messaging.InboundEmail email,
Messaging.InboundEnvelope envelope)
{
String subject = email.subject;
Pattern idPattern = Pattern.compile('500[A-Za-z0-9]{15}');
Matcher matcher = idPattern.matcher(subject);
if (!matcher.find()) System.assert(false, 'No Case Id in subject!');
Case caset = [SELECT Status, Priority FROM Case WHERE Id = :matcher.group(0)];
String[] emailBody = email.plainTextBody.split('\n', 0);
String Status1 = emailBody[0].substring(7);
String Priority1 = emailBody[1].substring(9);
caset.Status = Status1;
caset.Priority = Priority1;
update caset;
Messaging.InboundEmailresult result = new Messaging.InboundEmailResult();
result.message = 'Case Status is now' + caset.Status;
return result;
}
}
This should get you started. Tweak as you need
All Answers
Please see this article: http://blog.jeffdouglas.com/2010/03/12/writing-an-inbound-email-service-for-salesforce-com/
This should get you started. Tweak as you need
casestatus:XXXX:casestatus
in this case you just look for that pattern in the entire email body and parse anything in between casestatus: and :casestatus (We can take a cue from salesforce acitivity association using ref: :ref). That will eliminate many issues. Ofcourse, if you don't have control over the ticketing system that sends the email then it won't work.