0

I add a inbound email handler into my org to add a new record in a custom object (bt).

Sometime the mails are not processed and I don't know why. Is there a way to check the incoming mails in Salesforce?

can I enter a line in the code where the process should begin and end? Because sometimes is some text before or after the relevant points.

global class btFromEmail implements Messaging.InboundEmailHandler {
    
global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email, Messaging.InboundEnvelope envelope) {
    Messaging.InboundEmailResult result = new Messaging.InboundEmailResult();
    bt__c C = new bt__c(); 
        if(email.plainTextBody != Null && email.plainTextBody != '') {
            String[] emailBodyRows = email.plainTextBody.split('\n');
            for (String bodyRow:emailBodyRows) {
                String[] rowContents = bodyRow.split(':');
                String label = rowContents[0].trim();
                String value = rowContents[1].trim();
                switch on label {
                    when 'Firstname' {
                        c.Firstname__c = value;
                    }
                    when 'Lastname' {
                        c.Lastname__c = value;
                    }                 
                    when 'Birthdate' {
                         c.Birthdate__c = date.valueOf(value);
                    }                   
                    when 'Phone' {  
                        c.Phone_private__c = value;
                    }              
                    when 'Email' {        
                        c.E_mail_private__c = value;                                        
                    }                            
                }            
            }
        }
      insert c;             
      return result;
  }
    
}
1
  • 1
    is this an issue in production or can you reproduce the issue in sandbox? If the issue is sporadic, you might need to log to an sobject every incoming inbound email and the resulting bt__c inserted. Be sure you have apex exception emails configured correctly so any exceptions get reported to you.
    – cropredy
    Mar 11, 2021 at 19:15

1 Answer 1

0

Now I put all mails into a note, than I have an overview of mailtraffic.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.