I have the following Email handler Class:
global class InsertReplyEmail implements Messaging.InboundEmailHandler {
global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email, Messaging.InboundEnvelope envelope){
Messaging.InboundEmailResult result = new Messaging.InboundEmailResult();
if(email.subject.contains('Case:')){
system.debug(Email.subject);
String CaseNumberExtract = email.subject.substringAfter('Case:').deleteWhitespace();
Case c = [select id from Case where CaseNumber = :CaseNumberExtract];
EmailMessage newEmail = new EmailMessage();
newEmail.FromAddress = email.fromAddress;
newEmail.FromName = email.fromName;
newEmail.ToAddress = email.toAddresses[0];
newEmail.Subject = email.subject;
newEmail.TextBody = email.plainTextBody;
newEmail.HtmlBody = email.htmlBody;
newEmail.RelatedToID = c.id;
newEmail.Incoming = true;
insert newEmail;
}
return null;
}}
It's working fine but my issue is that all the emails are coming in with a status of 'Sent'. I want the status to be 'New'. I've tried to set the status as new in the below class but i get an error saying bad picklist value when i test the class.
Does anyone know how I can get the status to work as i'm hoping?