• Sharon Prager
  • NEWBIE
  • 10 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 3
    Replies
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;
  }
}
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!
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;
  }
}