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();

        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?

2 Answers 2


I think you can set the status value with the sequence number.

0 - New 1 - Read 2 - Replied 3 - Sent 4 - Forwarded 5 - Draft

So it could be like this

EmailMessage emailMessage = new EmailMessage();
emailMessage.status = '3'; // email was sent

No you cannot Customize the status Value to other than this as you wish.You can change values within this New, Read, Replied, Sent, Forwarded, or Draft. Email Is Incoming so Status will be sent.

enter image description here

Check here for Email Message Field Details

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .