+ Start a Discussion

Inbound Mail Handler Undeliverable email


I am trying to check the incoming mail for a specific id, which will then send an email whether the id is found or not.

No errors in class.
Class -

global class ProcessIncomingEmail implements Messaging.InboundEmailHandler {
      global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email, Messaging.InboundEnvelope envelope) {
          Messaging.InboundEmailResult result = new Messaging.InboundEmailresult();
          String mySubject = email.subject;
      String myReply = email.fromAddress;
          Id s = '35987239';
          Boolean b;
              b = mySubject.contains(s);
          List<Messaging.SingleEmailMessage> mails = new List<Messaging.SingleEmailMessage>();
          if (b == true) {
              Messaging.SingleEmailMessage successmail = new Messaging.SingleEmailMessage();
              successmail.setSenderDisplayName('Verification Update');
              successmail.setSubject('Your Id is found:');
          catch (System.QueryException e){
              System.debug('The issue is: ' + e);
          else    {
              Messaging.SingleEmailMessage failmail = new Messaging.SingleEmailMessage();
              failmail.setSenderDisplayName('Verification Update');
              failmail.setSubject('Your Id is not found:');
      result.success = true;
          return result;

But gives the below error when i try to send email to the Email Service Address.
Error -

This message was created automatically by the mail system.

A message that you sent could not be delivered to one or more of its
recipients. This is a permanent error. The following address(es) failed:

>>> idverification@blah_blah_blah.cs33.apex.sandbox.salesforce.com (Undelivered):
554 The apex class ProcessIncomingEmail failed due to: System.StringException: Invalid id: 35987239

Thanks for your help!!!
Best Answer chosen by LoneStar69
Hey Id in salesforce always should eith 15 or 18 digit ,Error is basically throwing from that line .

All Answers

Hi Mairuz,
Can you tell me one thing the id you have declared is for what 
 Id s = '35987239';
Error is coming from that only .

Please clarify .
Hi Manoj,

It's just a random Id i want to check in the incoming email subject.

Hey Id in salesforce always should eith 15 or 18 digit ,Error is basically throwing from that line .
This was selected as the best answer
Now it says,

(Undelivered): 554 The apex class ProcessIncomingEmail failed due to: System.EmailException: SendEmail failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Missing target address (target, to, cc, bcc): []
Made use of https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_email_outbound_single.htm